From 75f02b2c0bbd71670d91911d9ece0ea9714350d8 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sun, 13 Jan 2019 20:26:14 +0100 Subject: [PATCH] Generalize the bind operator in Async to sequences of arbitrary length --- async.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/async.js b/async.js index 6c9ef2c..53f6952 100644 --- a/async.js +++ b/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() {