Skip to content

Instantly share code, notes, and snippets.

@couto
Last active April 12, 2018 04:13
Show Gist options
  • Save couto/35e177283855b874d8a6 to your computer and use it in GitHub Desktop.
Save couto/35e177283855b874d8a6 to your computer and use it in GitHub Desktop.
ES5 version of curry
// curry :: (* -> a) -> (* -> a)
const curry = (fn) => function cf(...args){
return (args.length >= fn.length) ?
fn(...args) :
(...newArgs) => cf(...[...args, ...newArgs])
};
/**
* curry
*
* @param {Function} fn
* @param {Object} ctx
* @return {Function}
*/
var curry = function curry(fn, ctx){
return function cf(){
var args = [].slice.call(arguments);
return (args.length >= fn.length) ?
fn.apply(null, args) :
function () {
return cf.apply(ctx, args.concat([].slice.call(arguments)));
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment