-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currying? #3
Comments
I had the same question some days ago. Technically it isn't currying, because currying is a creation of a function, where partial application outputs a function with remaining arguments, which can be called, and its output can be called, until all arguments are applied. In a good implementation, curried functions should also be uncurriable. In javascript, it would look like this: const fn = (a, b, c) => a + b + c;
const curried = fn.curry();
curried(1)(2)(3); // 6
curried(1, 2); // (c) => ...
const uncurried = curriedFn.uncurry();
uncurried(1, 2, 3); // 6
uncurried(1, 2); // NaN And what author of this repository proposes, is the actual and explicit partial application, which isn't currying. But I must admit - P.S. Or even better, |
@stylemistake is correct; currying is making a function only ever take one argument. You can write curried functions today quite easily in JS: // currying!
var add = (x) => (y) => x + y
var result = add(10)(15)
result //=> 25 @stylemistake Be careful about how you express arguments. You say I chose function add(x, y) { return x + y }
var addTen = add.partialLeft(10) // <-- long!
var addTen = add.bind(null, 10)
var addTen = (y) => add(10, y)
var addTen = add.papp(10) Other languages such as Haskell and Elm don't have this problem because their functions are curried by default. But alas, we have JavaScript. P.S. |
I'm also sure that what ever name it would be it Must be short. Other way it's not better than rewriting with arrow function. Why Shortness is extremely important when you are inlining function inside another one like |
Thanks for the thorough explanations! |
Forgive my ignorance, but isn't "partial application" the same thing as "currying"? http://javascript.crockford.com/www_svendtofte_com/code/curried_javascript/
The text was updated successfully, but these errors were encountered: