Last active
July 2, 2017 07:16
-
-
Save GheorgheP/9351f16b51832cbc6d2e7565d20e8bcb to your computer and use it in GitHub Desktop.
composeAsync
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 composeAsync = (...fs) => { | |
if (fs.length === 0) { | |
throw new Error('compose requires at least one argument') | |
} | |
return async (...as) => { | |
const call = async fs => { | |
const f = fs[0] | |
const tail = fs.slice(1, Infinity) | |
return await tail.length === 0 ? f(...as) : f(await call(tail)) | |
} | |
return await call(fs) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function composition with for asynchronous functions.
Test: https://repl.it/HT3C/4