Created
May 26, 2017 21:15
-
-
Save pfrozi/0a4a050450cf80826e8c49cc85414185 to your computer and use it in GitHub Desktop.
This file contains 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
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