Created
January 28, 2017 05:35
-
-
Save ericelliott/eb176261f41d82c02460a2756fe8911a to your computer and use it in GitHub Desktop.
Autocurry
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 curry = fn => (...args1) => { | |
if (args1.length === fn.length) { | |
return fn(...args1); | |
} | |
return (...args2) => { | |
const args = [...args1, ...args2]; | |
if (args.length >= fn.length) { | |
return fn(...args); | |
} | |
return curry(fn)(...args); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment