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
R.prop and R.path inconsistency #1522
Comments
I'd forgotten that this was mentioned on Gitter. I was going to respond there, but some other conversation intervened. I believe someone there suggested that both should throw. I'm going to disagree. Functions that throw do not compose. While I have no problem leaving unspecified behavior fairly inconsistent, I think we should not throw here, and have module.exports = _curry2(function prop(p, obj) {
if (obj == null) {
return;
}
return obj[p];
}); What do others think? |
👍 for having both functions return undefined in that scenario. |
Agreed, I would also prefer to return undefined in both cases. |
In this case we're talking about a type mismatch – an error that would be caught at compile-time in a statically typed language. It's important not to conflate type mismatches with correctly typed operations which may fail. Types such as Looked at another way, how should |
@davidchambers Hm, well I suppose your line of argumentation is sound. I was looking at it from a more pragmatic perspective where a function returning undefined is more convenient to handle. An aside: You mention that we can encode failures in sum types. I would however assume that the majority of ramda users do not use it in combination with fantasyspec adhering Maybe/Either sum types. |
You're no doubt correct. I worry, though, about |
i'll be dead then |
As mentioned in gitter, I’ve found a scenario where the behavior of
R.path
differs fromR.prop
:IMHO if the path array of
R.path
contains only one element the function should be equivalent toR.prop
.The text was updated successfully, but these errors were encountered: