Created
December 13, 2013 09:15
-
-
Save cyjake/7941766 to your computer and use it in GitHub Desktop.
Auto currying function
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 multiply() { | |
// implementation code goes here | |
} | |
multiply(3)(4)(5) // ==> 60 |
Author
cyjake
commented
Dec 16, 2013
function autoCurry(fn) {
var args = []
return function curry() {
args = args.concat(Array.prototype.slice.call(arguments))
if (args.length === fn.length)
return fn.apply(null, args)
else
return curry
}
}
var multiply = autoCurry(function(a, b, c) {
return a * b * c
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment