Generalize the bind operator in Async to sequences of arbitrary length

This commit is contained in:
Tissevert 2019-01-13 20:26:14 +01:00
parent 5048fb134c
commit 75f02b2c0b

View file

@ -15,12 +15,24 @@ function Async() {
}; };
} }
function bind(m, f) { function bind() {
return function(g) { var m, steps, i;
m(function(x) { if(arguments.length < 1) {
f(x)(g); return wrap();
});
} }
m = arguments[0];
steps = arguments;
i = 1;
return function(f) {
var step = function(x) {
if(i < steps.length) {
steps[i++](x)(step);
} else {
return f(x);
}
}
m(step);
};
} }
function parallel() { function parallel() {