-
Notifications
You must be signed in to change notification settings - Fork 17
Supporing Records/Tuples and Maps #36
Comments
If this is a change we want to make, now that it's stage 3 we'll need to notify implementors quickly to ensure they don't ship |
There are lots of methods in the language which produce string-keyed collections. Should we generally want to add record-producing versions of all of them? I think no. We should instead make it easy to get a Record out of an object, so you can convert to the type you want if you want something non-default.
I don't think we should hide the strictly more useful (if slightly less ergonomic) version of And unless we add a new kind of collection which has a different kind of coercion applied to its keys (which I very much hope we don't do), To put it more briefly: no, I don't think we should add |
I agree, I personally don’t have any strong opinions about the other methods' return types, but to me, it makes sense for Tuple's On the other hand, if it should return a Building on the groupBy(arrayLike: Iterable | ArrayLike, groupfn: (value, index) => any, thisArg?: any) where: And like |
We support Map, and the Record & Tuple proposal can include a static |
tc39/proposal-record-tuple#275 brings up how
groupBy
could be supported on Tuples. Two open questions are:I think we can sidestep the first question for the time being (
Array.p.groupBy
groups into Arrays, and it wouldn't be weird for either choice to be chosen for Tuples).But, I think we should address the second question now. We currently have
Array.p.groupByToMap
, and I don't think adding a newgroupByToX
is a great solution for new return types. I think it'll be a bit weird to have:Array.p.groupBy
Array.p.groupByToMap
Array.p.groupByToRecord
(this would probably be bad, because how likely is it that the array is all primitives?)Tuple.p.groupBy
Tuple.p.groupByToMap
Tuple.p.groupByToRecord
@denk0403 suggests in #30 (comment) that we extend to new types by providing a static method on the constructor. Eg,
Array.p.groupBy(callback)
returns a prototype-less ObjectTuple.p.groupBy(callback)
returns a prototype-less ObjectMap.groupBy(iterable, callback)
returns a MapRecord.groupBy(iterable, callback)
returns a RecordThe text was updated successfully, but these errors were encountered: