Skip to content

Instantly share code, notes, and snippets.

@justinobney
Created October 6, 2019 19:23
Show Gist options
  • Save justinobney/e6115bfba404a2876ff4f61eb56df088 to your computer and use it in GitHub Desktop.
Save justinobney/e6115bfba404a2876ff4f61eb56df088 to your computer and use it in GitHub Desktop.
type composeFn<T> = (x: T) => T | Promise<T>;
function compose<T>(...fns: composeFn<T>[]) {
return async (x: T | Promise<T>): Promise<T> =>
fns.reduce((v, f) => (async () => f(await v))(), x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment