Created
October 17, 2018 09:20
-
-
Save euhmeuh/29d831307371febfecaf4fb6416b8372 to your computer and use it in GitHub Desktop.
Javascript composition
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 sequence() { | |
const funcs = arguments; | |
return function(x) { | |
return Array.from(funcs).reduce((x, func) => func.call(null, x), x); | |
}; | |
} | |
function compose() { | |
return sequence.apply(null, Array.from(arguments).reverse()); | |
} | |
const doIt = compose( | |
str => str+"!", | |
str => str.toUpperCase(), | |
str => str+"world", | |
); | |
console.log(doIt("hello")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment