Comparing version 1.0.1 to 1.1.0
@@ -6,5 +6,9 @@ /* | ||
"use strict"; | ||
var chain, map, ap, concat, liftM, liftM2, next, sequencea, sequence, mapM, foldM; | ||
(chain = (function(c, f) { | ||
return c.chain(f); | ||
var chain, map, ap, concat, liftM, liftM2, liftA, liftA2, next, sequencea, sequence, constant = (function(x) { | ||
return (function() { | ||
return x; | ||
}); | ||
}); | ||
(chain = (function(m, f) { | ||
return m.chain(f); | ||
})); | ||
@@ -30,6 +34,20 @@ (map = (function(f, m) { | ||
})); | ||
(liftA = (function(f, a) { | ||
return a.of(f) | ||
.ap(a); | ||
})); | ||
(liftA2 = (function(f, a1, a2) { | ||
return a1.of((function(x) { | ||
return (function(y) { | ||
return f(x, y); | ||
}); | ||
})) | ||
.ap(a1) | ||
.ap(a2); | ||
})); | ||
(next = (function(p, q) { | ||
return p.chain((function(_) { | ||
return q; | ||
})); | ||
var x; | ||
return p.chain(((x = q), (function() { | ||
return x; | ||
}))); | ||
})); | ||
@@ -49,6 +67,6 @@ (sequencea = (function(arr) { | ||
(exports["liftM2"] = liftM2); | ||
(exports["liftA"] = liftA); | ||
(exports["liftA2"] = liftA2); | ||
(exports["next"] = next); | ||
(exports["sequencea"] = sequencea); | ||
(exports["sequence"] = sequence); | ||
(exports["mapM"] = mapM); | ||
(exports["foldM"] = foldM); | ||
(exports["sequence"] = sequence); |
@@ -7,2 +7,6 @@ /* | ||
var base = require("./base"), | ||
liftA2 = base["liftA2"], | ||
__curry = (function(x, y) { | ||
return x.bind(null, y); | ||
}), | ||
Applicative, Chain, Functor, Monad, Monoid, Semigroup, Transformer; | ||
@@ -19,2 +23,7 @@ (Applicative = (function(Instance, of, ap) { | ||
}))); | ||
(Instance.ac = liftA2.bind(null, __curry)); | ||
(Instance.prototype.ac = (function(m) { | ||
var f = this; | ||
return liftA2(__curry, f, m); | ||
})); | ||
return Instance; | ||
@@ -21,0 +30,0 @@ })); |
{ | ||
"name": "akh", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Monad and Monad Transformer Collection", | ||
@@ -5,0 +5,0 @@ "author": "Matt Bierner", |
@@ -117,2 +117,65 @@ var Either = require('../index').either; | ||
test.done(); | ||
}; | ||
exports.ac = function(test) { | ||
var c = Either.of(function(x, y){return x / y;}) | ||
.ac(Either.of(10)) | ||
.ap(Either.of(5)) | ||
test.deepEqual( | ||
Either.either(c, l, r), | ||
[true, 2]); | ||
test.done(); | ||
}; | ||
exports.acn = function(test) { | ||
var c = Either.of([].concat.bind([])) | ||
.ac(Either.of(1)) | ||
.ac(Either.of(2)) | ||
.ac(Either.of(3)) | ||
.ac(Either.of(4)) | ||
.ac(Either.of(5)) | ||
.ap(Either.of(6)) | ||
test.deepEqual( | ||
Either.either(c, l, r), | ||
[true, [1,2, 3, 4, 5, 6]]); | ||
test.done(); | ||
}; | ||
exports.ac_no_apply = function(test) { | ||
var c = Either.of([].concat.bind([])) | ||
.ac(Either.of(1)) | ||
.ac(Either.of(2)) | ||
.ac(Either.of(3)) | ||
.ac(Either.of(4)) | ||
.ac(Either.of(5)) | ||
.ac(Either.of(6)) | ||
var result = Either.either(c, l, r); | ||
test.deepEqual( | ||
result[1](7), | ||
[1,2, 3, 4, 5, 6, 7]); | ||
test.done(); | ||
}; | ||
exports.ac_too_many = function(test) { | ||
var c = Either.of(function(x, y) {return x + y; }) | ||
.ac(Either.of(1)) | ||
.ac(Either.of(2)) | ||
.ac(Either.of(3)) | ||
.ac(Either.of(4)) | ||
.ac(Either.of(5)) | ||
.ap(Either.of(6)) | ||
test.deepEqual( | ||
Either.either(c, l, r), | ||
[true, 3]); | ||
test.done(); | ||
}; |
@@ -131,3 +131,3 @@ var List = require('../index').list; | ||
exports.ap = function(test) { | ||
exports.ap_one = function(test) { | ||
var c = List.of(function(x) { return x * 2; }) | ||
@@ -144,2 +144,36 @@ .ap(List.zero | ||
test.done(); | ||
}; | ||
}; | ||
exports.ap_many = function(test) { | ||
var c = List.of(function(x) { return x * 2; }) | ||
.concat(List.of(function(x) { return x + 10; })) | ||
.concat(List.of(function(x) { return x * x; })) | ||
.ap(List.zero | ||
.concat(List.of(1)) | ||
.concat(List.of(2)) | ||
.concat(List.of(3))); | ||
test.deepEqual( | ||
List.runList(c), | ||
[2, 4, 6, 11, 12, 13, 1, 4, 9]); | ||
test.done(); | ||
}; | ||
exports.ac = function(test) { | ||
var c = List.of(function(x, y) { return x * y; }) | ||
.ac(List.zero | ||
.concat(List.of(1)) | ||
.concat(List.of(2))) | ||
.ap(List.zero | ||
.concat(List.of(3)) | ||
.concat(List.of(4))); | ||
test.deepEqual( | ||
List.runList(c), | ||
[3, 4, 6, 8]); | ||
test.done(); | ||
}; |
60225
2027