-
-
Save dyaa/d42c4ddad0a70d943bea98bfc15f2bbe to your computer and use it in GitHub Desktop.
JavaScript one-line compose (ES6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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