Skip to content

Commit

Permalink
Merge pull request #136 from plaid/dc-apply
Browse files Browse the repository at this point in the history
function: assume that Function satisfies the requirements of Apply
  • Loading branch information
davidchambers committed Feb 2, 2016
2 parents 445aae5 + 9fe3518 commit d24a574
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
var Apply = $.TypeClass(
'sanctuary/Apply',
function(x) {
return _type(x) === 'Array' ||
return R.contains(_type(x), ['Array', 'Function']) ||
Functor.test(x) && hasMethod('ap')(x);
}
);
Expand All @@ -155,7 +155,7 @@
var Functor = $.TypeClass(
'sanctuary/Functor',
function(x) {
return _type(x) === 'Array' ||
return R.contains(_type(x), ['Array', 'Function']) ||
hasMethod('map')(x);
}
);
Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ var parseHex = function(s) {
return n !== n ? S.Left('Invalid hexadecimal string') : S.Right(n);
};

// positive :: Number -> Boolean
var positive = function(n) { return n > 0; };

// rem :: (Number, Number) -> Number !
var rem = function(x, y) {
if (y === 0) {
Expand Down Expand Up @@ -381,6 +384,9 @@ describe('function', function() {

eq(S.lift(R.multiply(2), [1, 2, 3]), [2, 4, 6]);
eq(S.lift(R.multiply(2), []), []);

eq(S.lift(S.not, S.even)(42), false);
eq(S.lift(S.not, S.even)(43), true);
});

});
Expand Down Expand Up @@ -408,6 +414,11 @@ describe('function', function() {

eq(S.lift2(R.add, [1, 2], [10, 20]), [11, 21, 12, 22]);
eq(S.lift2(R.add, [], [1, 2]), []);

eq(S.lift2(S.and, S.even, positive)(42), true);
eq(S.lift2(S.and, S.even, positive)(43), false);
eq(S.lift2(S.and, S.even, positive)(-42), false);
eq(S.lift2(S.and, S.even, positive)(-43), false);
});

});
Expand Down Expand Up @@ -435,6 +446,8 @@ describe('function', function() {

eq(S.lift3(R.reduce, [R.add], [0], [[1, 2, 3]]), [6]);
eq(S.lift3(R.reduce, [R.add], [0], []), []);

eq(S.lift3(R.curry(area), R.dec, S.I, R.inc)(4), 6);
});

});
Expand Down

0 comments on commit d24a574

Please sign in to comment.