Created
July 26, 2020 10:29
-
-
Save jmaicaaan/6e51d25635b025762866ac3a7578c39f to your computer and use it in GitHub Desktop.
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
// fusion approach | |
const data = [ | |
1, | |
2, | |
3, | |
4, | |
5, | |
]; | |
/** | |
* | |
* This utility function is often available on various | |
* functional libraries (i.e ramdajs) | |
* `pipe` is the opposite of `compose` | |
*/ | |
const pipe = (...fns) => initialValue => fns.reduce((result, fn) => fn(result), initialValue); | |
const add = (x) => x + 1; | |
const multiplyBy2 = (x) => x * 2; | |
const res = data | |
.map( | |
pipe(add, multiplyBy2) | |
) | |
// [ 4, 6, 8, 10, 12 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment