Last active
June 3, 2018 01:33
-
-
Save andycarrell/b7fa9b71a3ed0762299f1e4cd376383f to your computer and use it in GitHub Desktop.
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) => x => [...fns].reverse().reduce((acc, fn) => fn(acc), x); | |
const compose = (...fns) => { | |
const [first, ...rest] = [...fns].reverse(); | |
return (...args) => rest.reduce((acc, fn) => fn(acc), first(...args)); | |
} |
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 pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x); | |
// const compose = (...fns) => pipe([...fns].reverse()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment