Created
March 31, 2018 12:12
-
-
Save mtavkhelidze/896d608aee8fc85b14217062c0995313 to your computer and use it in GitHub Desktop.
Curry any JavaScript function as many times as you like.
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.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