Skip to content

Commit

Permalink
Merge pull request #171 from plaid/dc-sanctuary-def
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Apr 11, 2016
2 parents f8ace0e + 8e4607d commit d741cbe
Show file tree
Hide file tree
Showing 5 changed files with 1,610 additions and 226 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ README.md: index.js
--heading-level 4 \
--url 'https://github.com/plaid/sanctuary/blob/v$(VERSION)/{filename}#L{line}' \
-- $^ \
| sed 's/<h4 name="\(.*\)#\(.*\)">\(.*\)\1#\2/<h4 name="\1.prototype.\2">\3\1#\2/' >'$@'
| LC_ALL=C sed 's/<h4 name="\(.*\)#\(.*\)">\(.*\)\1#\2/<h4 name="\1.prototype.\2">\3\1#\2/' >'$@'


.PHONY: lint
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"dependencies": {
"ramda": "0.21.x",
"sanctuary-def": "0.4.x"
"sanctuary-def": "0.5.x"
},
"ignore": [
"/.git/",
Expand Down
32 changes: 25 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@
//.
//. ```javascript
//. S.inc('XXX');
//. // ! TypeError: ‘inc’ expected a value of type FiniteNumber as its first argument; received "XXX"
//. // ! TypeError: Invalid value
//. //
//. // inc :: FiniteNumber -> FiniteNumber
//. // ^^^^^^^^^^^^
//. // 1
//. //
//. // 1) "XXX" :: String
//. //
//. // The value at position 1 is not a member of ‘FiniteNumber’.
//. ```
//.
//. Compare this to the behaviour of Ramda's unchecked equivalent:
Expand Down Expand Up @@ -312,7 +320,6 @@
$.NonZeroFiniteNumber,
$Either,
$.Integer,
List,
$Maybe,
$.RegexFlags,
TypeRep,
Expand All @@ -329,11 +336,21 @@

var def = $.create(checkTypes, env);

// Note: Type checking of method arguments takes place once all arguments
// have been provided (whereas function arguments are checked as early as
// possible). This is not ideal, but provides two benefits:
//
// - accurate type signatures in error messages (though "->" appears in
// place of "~>"); and
//
// - intuitive ordering (`a.m(b, c)` is checked in a-b-c order rather
// than b-c-a order).
var method = function(name, constraints, types, _f) {
var f = def(name, constraints, types, _f);
return def(name, constraints, R.tail(types), function() {
return R.apply(f, R.prepend(this, arguments));
});
return def(name,
constraints,
R.repeat($.Any, types.length - 1),
function() { return R.apply(f, R.prepend(this, arguments)); });
};

//. ### Classify
Expand Down Expand Up @@ -1146,7 +1163,7 @@
var toMaybe = S.toMaybe =
def('toMaybe',
{},
[$.Any, $Maybe(a)],
[a, $Maybe(a)],
function(x) { return x == null ? Nothing() : Just(x); });

//# maybe :: b -> (a -> b) -> Maybe a -> b
Expand Down Expand Up @@ -2839,7 +2856,8 @@
{},
[$.RegExp, $.String, $Maybe($.Array($Maybe($.String)))],
function(pattern, s) {
return R.map(R.map(toMaybe), toMaybe(s.match(pattern)));
var match = s.match(pattern);
return match == null ? Nothing() : Just(R.map(toMaybe, match));
});

//. ### String
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"ramda": "0.21.x",
"sanctuary-def": "0.4.x"
"sanctuary-def": "0.5.x"
},
"devDependencies": {
"doctest": "0.10.x",
Expand Down
Loading

0 comments on commit d741cbe

Please sign in to comment.