Created
August 24, 2019 15:54
-
-
Save caderek/e57475ff1c89bab7ebeabb8750ef5824 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 compose = (...fns) => x => fns.reduceRight((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; | |
/* | |
Note: function application order is | |
bottom-to-top: | |
*/ | |
const h = compose( | |
trace('after f'), | |
f, | |
trace('after g'), | |
g | |
); | |
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