-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
_.property support for null and undefined #1520
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
Conversation
|
👍 LGTM A simpler use case can be: var arrays = [[1, 2], null, [3]];
_.min(arrays, _.property('length')); // => [3] |
|
-1, people should handle |
|
This change should extend to |
It's not difficult in this case, either: _.min(_.filter(arrays, Boolean), _.property('length')); |
|
Unless there's a compelling use case for silently swallowing the error, Michael is right... |
I think Michael is actually wrong on this. Methods like |
|
What benefit do explicit How many times do you see code that looks like this |
|
@jdalton: I think Michael would rather see an inconsistency here than have this function adopt the poor semantics of other underscore functions. I also think nobody's definition of right/wrong in this thread is objective, so we should avoid using those terms. |
|
Talking about yourself in the third person is odd ;) |
|
Devs can save themselves their own grief if they just pay attention to the types of the values they're working with. I'm not convinced underscore should gloss over it for them. |
|
I rely on the behavior of ignoring nullish values. It saves me extraneous checks and is a great convenience. I'm also aware of the potential types, usually |
This is ad hominem and not pertinent. The fact of the matter is that sometimes nullish values will sneak through. The question is whether or not |
|
Not ad hominem because I am not trying to discredit @jdalton in order to discredit his argument. Instead, I am arguing that "saving devs grief" would be letting them know (via runtime |
|
I wasn't referring to @jdalton. I meant users of values that are sometimes null. You're discrediting their use of a sometimes null value to discredit |
Having It is similar to using
|
|
👍 makes sense and is consistent with the rest of the lib |
_.property support for null and undefined
|
Gotta love having a record of these conversations. I had a similar problem years ago, and I was on the fuzzy null side of the argument. According to this convo, it seems the balkanised opinions on the matter still continued for many years (maybe even after this merge). Although too late to save the state of my app at the time, I'm glad that pluck can now handle jagged data. |
The _.property method will currently throw an error if the returned function is passed in a
nullorundefinedvalue. With this PR, in such a caseundefinedwill be returned instead. This seems to be the least surprising behaviour as opposed to crashing the program.contrived example: