Skip to content

Instantly share code, notes, and snippets.

@munkacsitomi
Last active February 26, 2020 20:08
Show Gist options
  • Save munkacsitomi/71cf5b84d9e634f71cb2128a928f2caf to your computer and use it in GitHub Desktop.
Save munkacsitomi/71cf5b84d9e634f71cb2128a928f2caf to your computer and use it in GitHub Desktop.
<3 JS
const add = (a) => (b) => a + b;
const addMore = (a) => (b) => (c) => add(a)(b) + c;
console.log(add(2)(4));
console.log(addMore(2)(4)(6));
// 6
// 12
const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x);
const trace = label => value => {
console.log(`${label}: ${value}`);
return value;
};
const g = n => n + 1;
const f = n => n * 2;
const h = pipe(g, trace('after g'), f, trace('after f'));
h(20);
// after g: 21
// after f: 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment