-
Notifications
You must be signed in to change notification settings - Fork 5
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
Can we go ahead and add a pick/omit combined function to this proposal? #13
Comments
Can you elaborate on the use cases you have here? |
I think
The reason to mention it in this proposal is precisely because it is so intimately related to these two functions (again, it is either the composition, or arguably the ancestor of them). Perhaps more importantly though, you can kind of think of JavaScript as already supporting // To "omit" `a`, `b`, and `c`, notice we do still get to "keep" a, b, and c without further work:
const { a, b, c, ...objectWithOmissions } = someObject;
^ "omitted" |
| "picked"
// Alternatively, if you wish "pick" a, b, and c, you can do the same thing:
const { a, b, c, ...omittedItems } = someObject;
^ "picked" |
| "omitted" The key to |
partitioning an array does, but partitioning an object isn't something i'm familiar with. In general, the pushback this proposal got from committee was against dynamic functions - iow, the preference was static syntax forms, not dynamic function APIs. |
I mean, they're all just operating on objects, right ;)? We just currently only have a
Sure, but this makes this proposal no more or less dynamic, it just provides a convenience method, and performance improvement, for having to use both of these, which I at least run into all the time. In the package.json case, if you start having multiple keys with "dev" prefixes, it would be quite useful to do: const [devConfiguration, configuration] = partition(packageJSON, key => key.startsWith("dev"));
doStuff(configuration);
if (dev)
doStuff(devConfiguration) Separately, as a general defense of this proposal, with respect to the pushback for "dynamicism" vs. syntanctic forms, this feels like saying we shouldn't have |
Conceptually there's a huge difference between an array and a non-array object. |
The problem is that in JavaScript, objects do double duty as "Record" and "HashMap". There's perhaps a huge difference if we consider them records, but I think we have to also consider the very very common HashMap use case, especially considering we won't be getting |
Yeah, I wish those existed for objects as well, but they don't. The API available for dealing with objects is quite small, and it seems that's intentional. When an Object.map() proposal was presented, they were concerned about the "slippery slope" effect it would have in causing all sorts of other array-like methods to be requested to be available for objects, so the proposal tried to be morphed to be more generalized, then it was ultimately dropped. |
To put it simply, there are two problems we discuss here:
|
Oftentimes when I use these operations, I use them in conjunction, so instead of having to iterate over the same object twice, can we have something like
partition
added as a third method here:pick
andomit
could be defined in terms ofpartition
, or vice versaThe text was updated successfully, but these errors were encountered: