Skip to content

Instantly share code, notes, and snippets.

@pfrozi
Created May 26, 2017 21:15
Show Gist options
  • Save pfrozi/0a4a050450cf80826e8c49cc85414185 to your computer and use it in GitHub Desktop.
Save pfrozi/0a4a050450cf80826e8c49cc85414185 to your computer and use it in GitHub Desktop.
const g = n => n + 1;
const f = n => n * 2;
const trace = label => value => {
console.log(`${ label }: ${ value }`);
return value;
};
const doStuff = x => {
const afterG = g(x);
trace('after g')(afterG);
const afterF = f(afterG);
trace('after f')(afterF);
return afterF;
};
const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x);
const dostuffPiped = x =>
pipe(
g,
trace('after g'),
f,
trace('after f')
)(x);
doStuff(20);
dostuffPiped(20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment