Last active
June 14, 2020 16:20
-
-
Save CodHeK/92cb207b5659faf1fdb33bef15df49ee to your computer and use it in GitHub Desktop.
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 = (func) => { | |
return (a) => { | |
return (b) => { | |
return (c) => { | |
return func(a, b, c); | |
} | |
} | |
} | |
} | |
const add = (a, b, c) => a + b + c; | |
console.log(add(1, 2, 3)); // 6 | |
const f = curry(add); | |
/* | |
Our curry function should be able to pull off | |
something that lets us do this! | |
*/ | |
const f1 = f(1); | |
const f2 = f1(2); | |
const res = f2(3); // in the end calls add(1, 2, 3) giving 6. | |
/* | |
You can see how the previous arguments are stored | |
in the scope of the returned function | |
*/ | |
console.log(res); // 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment