Skip to content

Instantly share code, notes, and snippets.

@dyaa
Forked from WaldoJeffers/compose.js
Created April 17, 2018 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyaa/d42c4ddad0a70d943bea98bfc15f2bbe to your computer and use it in GitHub Desktop.
Save dyaa/d42c4ddad0a70d943bea98bfc15f2bbe to your computer and use it in GitHub Desktop.
JavaScript one-line compose (ES6)
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)))
// Usage : compose functions right to left
// compose(minus8, add10, multiply10)(4) === 42
//
// The resulting function can accept as many arguments as the first function does
// compose(add2, multiply)(4, 10) === 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment