Last active
September 25, 2016 02:59
-
-
Save nicolasparada/8b7ef29abeec3dc8790723683299f34c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const waterfall = (array = []) => { | |
const iterate = index => (...args) => { | |
const fn = array[index] | |
const next = iterate(index + 1) | |
return fn ? | |
Promise.resolve(fn(...args, next)) : | |
Promise.resolve(...args) | |
} | |
try { | |
return iterate(0)() | |
} catch (ex) { | |
return Promise.reject(ex) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: