/* * curry(fn: Function) => Function * Simple implementation of currying a function * Drawbacks: * - Cannot be reused as stored args is mutable * - Cannot use placeholders * - Will not check argument overflow */ function curry(fn) { var arity = fn.length; // check the arity of the given function var args = []; // store all arguments here function curried() { // the curried function args = args.concat(Array.prototype.slice.call(arguments)); if (arity <= args.length) { return fn.apply(null, args); // call the function with all the arguments } return curried; // otherwise return the curried function to be given more arguments } return curried; }