-
-
Save wayneseymour/4e6a5ba5c5b02f287ef99f239c4b5d78 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