-
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
groupBy: Treat holes as undefined #19
Conversation
What about holes in What about the prototype returned |
We're rejecting (🥁 ) the plain object. It'll either be a prototype-less object or a Map, with the possibility of having 2 methods to switch between the two return values. Also, |
const { foo = [], bar = [], baz = [] } = array.groupBy(fn);
// vs
const result = array.groupBy(fn);
const foo = result.get('foo') ?? [];
const bar = result.get('bar') ?? [];
const baz = result.get('baz') ?? []; We already have a recent precedent of const { foo, bar, baz } = regex.exec(string).groups; |
That's indeed the arguments for a null object; the arguments for Map are that some do want to group by "not just property keys". |
It's not harder to iterate over |
I agree; but if someone wants to group by an object or a boolean or a number or something, an object wouldn't let them do it. |
I agree with the ergonomic argument for preferring an object, primarily for destructuring (I imagine this will be a popular usage). I think Maps are a more pure form of data structure because they can handle any key and not just property keys, and it's possible that some users will want to take advantage of that. I think the primary form should be the object return value, with some way to use a Map if necessary for the user. |
That makes sense. So, |
That's my expectation. We could either have |
This standardizes on the common ES6+ precedent (though it was ignored by
flat
andflatMap
) where array holes are treated asundefined
. In ES5 code, holes were skipped (callbackfn
is not called).This does have the following side-effect:
We've explicitly transformed a hole into an
undefined
in the false grouping.