forked from puffnfresh/bilby.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo.js
59 lines (52 loc) · 1.11 KB
/
do.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var λ = require('./lib/test');
exports.monadTest = function(test) {
test.equal(
λ.Do()(
λ.some(1) >= function(x) {
return x < 0 ? λ.none : λ.some(x + 2);
}
).getOrElse(0),
3
);
test.done();
};
exports.kleisliTest = function(test) {
test.equal(
λ.Do()(
function(x) {
return x < 0 ? λ.none : λ.some(x + 1);
} >> function(x) {
return x % 2 !== 0 ? λ.none : λ.some(x + 1);
}
)(1).getOrElse(0),
3
);
test.done();
};
exports.functorTest = function(test) {
test.equal(
λ.Do()(
λ.some(1) < λ.add(2)
).getOrElse(0),
3
);
test.done();
};
exports.applicativeTest = function (test) {
test.equal(
λ.Do()(
λ.some(λ.add) * λ.some(1) * λ.some(2)
).getOrElse(0),
3
);
test.done();
};
exports.semigroupTest = function (test) {
test.equal(
λ.Do()(
λ.some(1) + λ.some(2)
).getOrElse(0),
3
);
test.done();
};