Skip to content

Instantly share code, notes, and snippets.

@CodHeK
Last active June 14, 2020 16:20
Show Gist options
  • Save CodHeK/92cb207b5659faf1fdb33bef15df49ee to your computer and use it in GitHub Desktop.
Save CodHeK/92cb207b5659faf1fdb33bef15df49ee to your computer and use it in GitHub Desktop.
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