Last active
October 8, 2017 16:31
-
-
Save aSapien/4154bc7dcc324b6662904bc80b4436e6 to your computer and use it in GitHub Desktop.
A small utility function to compose functions, lazily evaluated
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 compose(func, ...funcs) { | |
return function(...args) { | |
return funcs.length > 0 | |
? compose(...funcs)(func(...args)) | |
: func(...args) | |
} | |
} | |
// Or, in a more compact version: | |
const compose = (func, ...funcs) => (...args) => | |
funcs.length > 0 ? compose(...funcs)(func(...args)) : func(...args); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment