Last active
December 17, 2016 18:50
-
-
Save m3g4p0p/9c0656ec6563f2caf2c1ee8f8853c5ca to your computer and use it in GitHub Desktop.
JS currying
This file contains hidden or 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
const curry = (fn, thisArg) => function accumulate (...args) { | |
return args.length < fn.length | |
? accumulate.bind(null, ...args) | |
: fn.apply(thisArg, args) | |
} | |
const fn = (a, b, c) => a + b + c | |
curry(fn)(1)(2)(3) // 6 | |
curry(fn)(1)(2, 3) // 6 etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment