Skip to content

Instantly share code, notes, and snippets.

@christianscott
Created March 8, 2018 01:02
Show Gist options
  • Save christianscott/8f72fdcaefeb76f5f3038ee5e9bca7c3 to your computer and use it in GitHub Desktop.
Save christianscott/8f72fdcaefeb76f5f3038ee5e9bca7c3 to your computer and use it in GitHub Desktop.
Curry a function in Javascript to allow partial application
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