Skip to content

Instantly share code, notes, and snippets.

@sebabouche
Created January 28, 2018 16:35
Show Gist options
  • Save sebabouche/c32aa328448abaa701e2d831472eed13 to your computer and use it in GitHub Desktop.
Save sebabouche/c32aa328448abaa701e2d831472eed13 to your computer and use it in GitHub Desktop.
A pipeline of transformations example using reduce
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