Skip to content

Instantly share code, notes, and snippets.

@christianwish
Last active November 8, 2021 16:42
Show Gist options
  • Save christianwish/eb01dcc6525bdfd1d5e6f0d12547af8f to your computer and use it in GitHub Desktop.
Save christianwish/eb01dcc6525bdfd1d5e6f0d12547af8f to your computer and use it in GitHub Desktop.
export type COMPOSE = <T>(fn1: (a: T) => T, ...fns: Array<(a: T) => T>) =>
(a: T) => T
export const compose: COMPOSE = (fn1, ...fns) =>
fns.reduce(
(prevFn, nextFn) =>
(value) => prevFn(nextFn(value)),
fn1
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment