Skip to content

Instantly share code, notes, and snippets.

@lionelB
Forked from WaldoJeffers/compose.js
Created May 1, 2017 13:21
Show Gist options
  • Save lionelB/137adad9e2cf1f49208d9c8b48051437 to your computer and use it in GitHub Desktop.
Save lionelB/137adad9e2cf1f49208d9c8b48051437 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