Skip to content

Instantly share code, notes, and snippets.

@tsaiDavid
Last active July 7, 2018 16:16
Show Gist options
  • Save tsaiDavid/fba7600ad0a96c1ad70398811068695a to your computer and use it in GitHub Desktop.
Save tsaiDavid/fba7600ad0a96c1ad70398811068695a to your computer and use it in GitHub Desktop.
// Curry Function as shown in "Hardcore Functional Programming in JS"
function curry(fn) {
return function () {
// if there are fewer provided args than originally intended
if (fn.length > arguments.length) {
var slice = Array.prototype.slice
var args = slice.apply(arguments)
// return another fn that can 'delay' application of other args
return function () {
return fn.apply(null, args.concat(slice.apply(arguments)))
}
}
// otherwise, just pass along the args in full
return fn.apply(null, arguments)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment