Skip to content

Instantly share code, notes, and snippets.

@andycarrell
Last active June 3, 2018 01:33
Show Gist options
  • Save andycarrell/b7fa9b71a3ed0762299f1e4cd376383f to your computer and use it in GitHub Desktop.
Save andycarrell/b7fa9b71a3ed0762299f1e4cd376383f to your computer and use it in GitHub Desktop.
const compose = (...fns) => x => [...fns].reverse().reduce((acc, fn) => fn(acc), x);
const compose = (...fns) => {
const [first, ...rest] = [...fns].reverse();
return (...args) => rest.reduce((acc, fn) => fn(acc), first(...args));
}
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
// const compose = (...fns) => pipe([...fns].reverse());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment