Skip to content

Instantly share code, notes, and snippets.

@gapurov
Forked from WaldoJeffers/compose.js
Created November 27, 2018 16:27
Show Gist options
  • Save gapurov/af0d53f5ed674df78b15d4b865e03744 to your computer and use it in GitHub Desktop.
Save gapurov/af0d53f5ed674df78b15d4b865e03744 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