Created
March 28, 2018 21:30
-
-
Save dmitrymatveev/c9724ebcb076fa8c918ea5d66b801b66 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 HEAD = 0; | |
const splitCallback = list => [ | |
list.slice(0, list.length - 1), | |
list[list.length - 1] | |
]; | |
function next(args, done, ...functions) { | |
const fnc = functions[HEAD]; | |
if (!fnc) done(); | |
else fnc(...args, err => { | |
if (err) done(err); | |
else next(args, done, ...functions.slice(1)) | |
}); | |
} | |
export const waterfall = (...functions) => (...args) => next(...splitCallback(args), ...functions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment