Last active
July 5, 2016 19:12
-
-
Save mckomo/1876cb605975fca4ce7fc81e13c73f35 to your computer and use it in GitHub Desktop.
JS implementation of curry function with some ES6 sugar.
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) { | |
const arity = fn.length; | |
const curring = function() { | |
var args = asArray(arguments); | |
if (args.length >= arity) { | |
return fn(... args); | |
} | |
return function() { | |
return curring(... args.concat(asArray(arguments))); | |
}; | |
} | |
const asArray = parameters => Array.prototype.slice.call(parameters, 0); | |
return curring; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment