Skip to content

Instantly share code, notes, and snippets.

@suissa
Forked from WaldoJeffers/compose.js
Created October 21, 2017 02:03
Show Gist options
  • Save suissa/3480a84cce460fafc7f527fbe24d7f2e to your computer and use it in GitHub Desktop.
Save suissa/3480a84cce460fafc7f527fbe24d7f2e 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