Last active
January 9, 2019 12:14
-
-
Save ithinkihaveacat/f9525c8f99753560cde5b64ae1781e38 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
function compose<T>(...fna: Array<(p: T) => Promise<T>>) { | |
return (p: T) => { | |
return fna.reduce((a, fn) => a.then(fn), Promise.resolve(p)); | |
}; | |
} | |
const pipe = compose(foo, bar, baz); | |
const res1 = pipe(arg); | |
// equivalent | |
const res2 = foo(arg).then(bar).then(baz); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment