-
Notifications
You must be signed in to change notification settings - Fork 87
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
flip doesn't work when arity > 2 #464
Comments
I agree that the method the least should throw instead of returning The limitation of I thank you for pointing out that As for R.flip - I wll try once again to make it work for 3 arguments and if I cannot make it, at least the function will throw. |
Here is a version that works with 3 arguments: function flipExport(fn) {
const flipedFn = (...input) => {
const missing = fn.length - input.length;
if (missing <= 0)
return fn(input[1], input[0], ...input)
if (input.length === 0)
return flipedFn
if (input.length === 1)
return curryN(missing, (...rest) => {
const args = [rest[0], input[0], ...rest.slice(1)]
return fn(...args)
})
// input.length >= 2
return curryN(missing, (...rest) => {
const args = [input[1], input[0], ...input.slice(2), ...rest]
return fn(...args)
})
}
return flipedFn
} However it requires function curry(fn) {
return curryN(fn.length, fn)
} |
Sounds good to me. Can you open a PR for that? Just edit |
Actually, I could make your solution work, so I increased the supported arity of |
This is a difference with ramda and should either be documented as such or be made compatible.
If it's not made compatible, a more reasonable behavior than
return undefined
should be used, egthrow new Error("flip doesn't work with arity > 2")
.rambda/src/flip.js
Lines 1 to 11 in f8f3895
Note: just reviewed the doc, there is a small box saying
Reason for the failure is...
at the bottom of theflip
section, but it doesn't grab the attention enough, usually a red flair or a warning icon is used in this kind of contextThe text was updated successfully, but these errors were encountered: