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
Curry #72
Comments
Can you show an example of how that would work? |
@elderhsouza yes, you right, it was just an example, we have to define arity const curry = (fn, arity = fn.length, ...args) =>
arity <= args.length
? fn(...args)
: curry.bind(null, fn, arity, ...args)
// curry(Math.pow)(2)(10) -> 1024
// curry(Math.min, 3)(10)(50)(2) -> 2 |
@elderhsouza the curry may not work const curry = (f, arity = f.length, next) =>
(next = prevArgs =>
nextArg => {
const args = [ ...prevArgs, nextArg ];
return args.length >= arity ? f(...args) : next(args);
}
)([]);
// curry(Math.min, 3)(10, 200)(2) -> not work I think should like this const curry = (f, arity = f.length, next) =>
(next = prevArgs =>
(...nextArg) => {
const args = [ ...prevArgs, ...nextArg ];
return args.length >= arity ? f(...args) : next(args);
}
)([]); |
@broadsw0rd I like this one, haven't used currying like this one yet, but I can see how it can be useful, solid implementation. @linrui1994 That's really elegant and terse, I tested all versions with the same use cases and it seems to work for all of it. @Chalarangelo Great discussion here, wanna jump in? |
If it works better than the previous one or covers more use-cases, PR it. I like what I see. 😉 |
Anybody wanna open a PR for this? I'd be glad to merge. |
@Chalarangelo Done! 👍 |
Resolved in #124. Closing... |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks. |
What about this kind of curry?
The text was updated successfully, but these errors were encountered: