-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
35 lines (29 loc) · 803 Bytes
/
index.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
// Dedicated to the public domain with the CC0/1.0 license
"use strict"
var Do = function(gen, m) {
var doing = gen();
var doRec = function(v){
var a = doing.next(v);
if(a.done) {
return m.of(a.value);
} else {
return a.value.chain(doRec);
}
};
return doRec(null);
};
Do.Multi = function(gen, m) {
var doRec = function(v, stateSoFar){
// okay, let's make this sucker!
var doing = gen();
stateSoFar.forEach(function(it){doing.next(it)});
var a = doing.next(v);
if(a.done) {
return m.of(a.value);
} else {
return a.value.chain(function(vv){return doRec(vv, stateSoFar.concat(v));})
}
};
return doRec(null, []);
};
module.exports = Do;