Skip to content

Instantly share code, notes, and snippets.

@mtavkhelidze
Created March 31, 2018 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtavkhelidze/896d608aee8fc85b14217062c0995313 to your computer and use it in GitHub Desktop.
Save mtavkhelidze/896d608aee8fc85b14217062c0995313 to your computer and use it in GitHub Desktop.
Curry any JavaScript function as many times as you like.
Function.prototype.curry = function () {
const slice = Array.prototype.slice;
const args = slice.apply(arguments);
const that = this;
return function () {
return that.apply(null, args.concat(slice.apply(arguments)));
};
};
const fn = (x1, x2, x3) => {
console.log(x1, x2, x3);
};
const fnOne = fn.curry(1);
const fnTwo = fnOne.curry("Two");
fnTwo("Tree");
fnTwo([7]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment