Created
June 27, 2016 05:32
-
-
Save stefanfrede/8bd9120393c6058228d3bf8e0ae2c6b9 to your computer and use it in GitHub Desktop.
Compose functions in data flow.
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 pipeline = (...fns) => | |
(value) => | |
fns.reduce((acc, fn) => fn(acc), value); | |
// Given: | |
const addOne = (number) => number + 1; | |
const doubleOf = (number) => number * 2; | |
// Instead of: | |
const doubleOfAddOne = (number) => doubleOf(addOne(number)); | |
// We could write: | |
const setter = pipeline(addOne, doubleOf); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment