Created
April 15, 2019 08:00
-
-
Save yairEO/7ed5750901a3e5ed31a4c1e271ddc95e to your computer and use it in GitHub Desktop.
Composition example
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
function last(n){ | |
return next => next - n; | |
} | |
function second(n){ | |
return next => next * n; | |
} | |
function first(n){ | |
return next => next + n; | |
} | |
var compose = (...funcs) => x => | |
funcs.reduceRight((accumulator, currentValue) => { | |
console.log(accumulator, currentValue) | |
return currentValue(accumulator) | |
}, x) | |
var chain = [last, second, first].map(f => f(2)); | |
console.warn( | |
compose(...chain)(10) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment