Skip to content

Instantly share code, notes, and snippets.

@annibuliful
Last active August 28, 2018 15:33
Show Gist options
  • Save annibuliful/bbd3a64516285042f5a65c640f08fe33 to your computer and use it in GitHub Desktop.
Save annibuliful/bbd3a64516285042f5a65c640f08fe33 to your computer and use it in GitHub Desktop.
pipe = (...fns) => x => fns.reduce((v, f) => f(v), x)
const array = [1, 2, 3, 4, 5, 6]
notEqualFive = (array) => {
console.log("first function running")
return array.filter((value) => {
console.log("not Equal five", value)
return value !== 5
})
}
filterSix = (array) => {
console.log("result from previos function", array)
console.log("second function runnning")
return array.filter((value) => {
console.log("six", value)
return value === 6
})
}
console.log(pipe(notEqualFive, filterSix)(array))
/* Step
* 1. I use notEqulFive() function to filter the values that are not equalt 5 then return them
* 2. After I use notEqualFive() function, I use filterSix() function to filter only value that is 6
*/
/* log
first function running
not Equal five 1
not Equal five 2
not Equal five 3
not Equal five 4
not Equal five 5
not Equal five 6
result from previos function [ 1, 2, 3, 4, 6 ]
second function runnning
six 1
six 2
six 3
six 4
six 6
[ 6 ]
*/
// If you want more information please click on link below
// https://medium.com/javascript-scene/reduce-composing-software-fe22f0c39a1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment