Skip to content

Instantly share code, notes, and snippets.

@ithinkihaveacat
Last active January 9, 2019 12:14
Show Gist options
  • Save ithinkihaveacat/f9525c8f99753560cde5b64ae1781e38 to your computer and use it in GitHub Desktop.
Save ithinkihaveacat/f9525c8f99753560cde5b64ae1781e38 to your computer and use it in GitHub Desktop.
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