-
-
Save vvatikiotis/c7e71e612ff4b9a6cd7cf721cdd4227b to your computer and use it in GitHub Desktop.
Autocurry
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 = 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