Created
April 23, 2017 06:51
-
-
Save GheorgheP/f593e5579ca945687b2005d460c9ec77 to your computer and use it in GitHub Desktop.
ES6 curry, with normal function behavior
This file contains hidden or 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 curry = f => { | |
const _curry = (args = []) => args.length < f.length ? (...a) => _curry([...args, ...a]) : f(...args) | |
return _curry() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the curried function either like a partial function
add(2)(3)
or normal functionadd(2, 3)
Example:
Dependency injection: