Last active
January 17, 2019 18:48
-
-
Save gl2748/c67475191c998c15396885b76c6860fc 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 x = 10 | |
const add = p => q => p + q; | |
const add1 = add(1) | |
const add2 = add(2) | |
// Note that here the accumulating value is itself a function. | |
const reducer = (acc, curr) => (...args) => { | |
return curr(acc(...args)); | |
}; | |
const compose = (...fns) => fns.reduce(reducer); | |
const calc = compose( | |
add1, | |
add2 | |
)(x) | |
// calc = 13 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment