Generalize the bind operator in Async to sequences of arbitrary length
This commit is contained in:
parent
5048fb134c
commit
75f02b2c0b
1 changed files with 17 additions and 5 deletions
22
async.js
22
async.js
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue