Created
March 8, 2018 01:02
-
-
Save christianscott/8f72fdcaefeb76f5f3038ee5e9bca7c3 to your computer and use it in GitHub Desktop.
Curry a function in Javascript to allow partial application
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
function curry(fn, ...initialArgs) { | |
return function (...nextArgs) { | |
const args = initialArgs.concat(nextArgs) | |
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