-
Notifications
You must be signed in to change notification settings - Fork 0
/
dest.js
39 lines (37 loc) · 935 Bytes
/
dest.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
var test = function () {
var $res = function ($monad) {
return $monad.bind([1, 2], function ($1) {
var a = $1;
return $monad.bind(test2(), function ($2) {
var b = $2;
return $monad.wrap(a + b);
});;
});;
};
$res.monadic = true;
return $res;
};
var test2 = function () {
var $res = function ($monad) {
return $monad.bind([1, 2], function ($1) {
return $monad.wrap($1);
});;
};
$res.monadic = true;
return $res;
};
function runList(m) {
if (!m.monadic) {
throw 'Hey, this is no monadic computation';
}
return m({
bind: function (x, f) {
var xx = x.monadic ? runList(x) : x;
return Array.prototype.concat.apply([], xx.map(f));
},
wrap: function (x) {
return [x];
}
});
}
console.log(runList(test()));