Forked from torgeir/javascript-autocurry-partial-application-of-any-level.js
Last active
August 29, 2015 14:06
-
-
Save malkomalko/30a0d23188a7602a4aa5 to your computer and use it in GitHub Desktop.
Autocurry functions in javascript
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
function curry(fn) { | |
var numargs = fn.length; | |
return createRecurser([]); | |
function createRecurser(acc) { | |
return function () { | |
var args = Array.prototype.slice.call(arguments); | |
return recurse(acc, args); | |
}; | |
} | |
function recurse(acc, args) { | |
var newacc = acc.concat(args); | |
if (newacc.length < numargs) { | |
return createRecurser(newacc); | |
} else { | |
return fn.apply(this, newacc); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment