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
1 changed files with 17 additions and 5 deletions

View File

@ -15,12 +15,24 @@ function Async() {
};
}
function bind(m, f) {
return function(g) {
m(function(x) {
f(x)(g);
});
function bind() {
var m, steps, i;
if(arguments.length < 1) {
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() {