Last active
May 6, 2018 19:20
-
-
Save niklasramo/7f9fe7acbb25f970792d2f21702b1063 to your computer and use it in GitHub Desktop.
This file contains 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) => fns.reduce((f, g) => (...args) => g(f(...args))); | |
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); | |
// Example | |
const addFoo = str => str + 'foo'; | |
const addBar = str => str + 'bar'; | |
const addFoobar = pipe(addFoo, addBar); | |
const addBarfoo = compose(addFoo, addBar); | |
addFoobar('hello ') // hello foobar | |
addBarfoo('hello ') // hello barfoo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment