Skip to content

Instantly share code, notes, and snippets.

@pofigizm
Last active September 1, 2017 06:57
Show Gist options
  • Save pofigizm/185b73a3d21e04eab291 to your computer and use it in GitHub Desktop.
Save pofigizm/185b73a3d21e04eab291 to your computer and use it in GitHub Desktop.
const pipe = (...args) => val => args.reduce((a,b) => b(a), val);
const foldl = fx => init => arr => [].reduce.call(arr, fx, init);
const fmap = fx => arr => [].map.call(arr, fx);
const arr = [1, 2, 3];
const fx1 = a => a * 2;
const fx2 = a => a - 2;
const fx3 = a => a * a;
const fx4 = (a, b) => a + b;
const piped = pipe(fx1, fx2, fx3);
const myMap = fmap(piped);
const myFoldl = foldl(fx4)(100);
const final = pipe(myMap, myFoldl);
console.log(final(arr)); // 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment