feat(support): withKeys and withoutKeys methods for manipulatesarray#2094
Conversation
innocenzi
left a comment
There was a problem hiding this comment.
I like the methods, but not the names; I don't think generic method names are helpful and I'd like to see more specific ones.
These are essentially "filter" methods, so maybe with should be an update to the existing filter where it accepts an array, and without should be a new reject method?
Well, given that it’s using diffKeys and intersectKeys under the hood, how about Filter I’m guessing already exists and will take a closure. Reject is fine but I think except or without fits it better? Edit: yep, filter takes a closure, and the issue with having it accept either a closure or Edit 2: given the intent behind your suggestion and the possibly ambiguity of using with or without at all (especially as with is sometimes a reserved operator in programming languages), I refactored to |
|
Y'all are going to hate me, but I'd love to be able to pass |
I’d say that’s what the |
Agree. Naming is hard 😅 I think there should be proper symmetry:
tbh my preference is |
|
I think my two pennies here is that whatever first part is chosen, that Keys should still suffix, that's the convention in use elsewhere within the class for when it explicitly works with Keys instead of Values. From a grammar perspective, the issue with "include" is it doesn't entirely communicate that it's an exclusive list, and in fairness, "with" also doesn't entirely communicate that it's an exclusive list. They both possibly imply "append" the values - whereas "only" clearly states that you're going to get "only" that back, which is the point of it. In the context of removing certain keys and getting the remainder, "except", "exclude", "remove", "without" all work. I did some searches and here's some more ideas that I think communicate "only" instead of "append":
Unrecommended ideas
|
|
I then say |
Refactored and clean qa locally, I imagine the checks will be along in a few :) |
|
Perfect! |
|
Well, didn't have time to weight in again but It's not the right name imo. It might be an unpopular opinion, but while stuff like "with" and "without" sound good in theory, they're hella confusing and I always end up having to look at what they actually do and compare it to other methods with similar generic names. I would really like it if we kept using explicit names 😔 There's also the issue of the names implying that the original array would be modified, which might not be the case depending on whether the instance is |
|
I’m really glad this point was raised, as I share exactly the same concerns regarding the The distinction between 'adding' and 'keeping' is a crucial one. To me, I'm afraid that Between the explicit options, I’d personally lean towards |
|
Well we didn't tag this yet, so no harm done. I don't really agree with you, but I also don't really care too much about it, so I'm fine changing it. Feel free to send a PR @innocenzi or @shaffe-fr or @iamdadmin with a better name. |
|
#2097 Enzo is on it! |
Suggested from #2092 - introduces convenience methods
->withKeysand->withoutKeysfor ManipulatesArray, and tests.Usage examples from the test: