Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Created July 26, 2020 10:29
Show Gist options
  • Save jmaicaaan/6e51d25635b025762866ac3a7578c39f to your computer and use it in GitHub Desktop.
Save jmaicaaan/6e51d25635b025762866ac3a7578c39f to your computer and use it in GitHub Desktop.
// 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