Created
December 9, 2015 16:23
-
-
Save monolithed/3e5fe601aac9d0ace54c to your computer and use it in GitHub Desktop.
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 currify(f) { | |
return function _currify(flen, _f) { | |
return (...args) => { | |
var remaining = flen - args.length; | |
return remaining <= 0 ? | |
_f(...args) : | |
_currify(remaining, (...args2) => _f(...args, ...args2)); | |
}; | |
}(f.length, f); | |
} | |
function add(a, b, c) { return a + b + c; } | |
var _add = currify(add); | |
console.log(_add(1)(2)(3)); | |
console.log(_add(1, 2)(3)); | |
console.log(_add(1)(2, 3)); | |
console.log(_add(1, 2, 3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment