Created
January 28, 2018 16:35
-
-
Save sebabouche/c32aa328448abaa701e2d831472eed13 to your computer and use it in GitHub Desktop.
A pipeline of transformations example using reduce
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 increment = input => input + 1 | |
const decrement = input => input - 1 | |
const double = input => input * 2 | |
const halve = input => input / 2 | |
const initialValue = 10 | |
const pipeline = [ | |
increment, | |
double, | |
decrement, | |
increment, | |
double, | |
increment, | |
double, | |
] | |
const finalValue = pipeline.reduce((acc, el) => el(acc), initialValue) | |
console.log(finalValue) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment