Created
March 30, 2018 05:55
-
-
Save uinz/b9991d255e19a3aeacecbb2b5a5b1def to your computer and use it in GitHub Desktop.
curry
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
function curry(func) { | |
return function caller(...args) { | |
if (args.length >= func.length) { | |
return func(...args) | |
} else { | |
return (..._args) => caller(...args, ..._args) | |
} | |
} | |
} | |
function add(a, b, c) { | |
return a + b + c | |
} | |
const cAdd = curry(add) | |
console.log( | |
cAdd(1, 2)(3, 4) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment