tc39 / proposal-array-filtering

A proposal to make filtering arrays easier
https://tc39.es/proposal-array-filtering/
MIT License
174 stars 5 forks source link

%TypedArray% methods #20

Open zloirock opened 3 years ago

zloirock commented 3 years ago

Sure, methods from this proposal should have equal on %TypedArray%.

The question: how should work %TypedArray%.prototype.groupBy?

jridgewell commented 3 years ago

Sure, methods from this proposal should have equal on %TypedArray%.

Yup. Strangely flatMap is also missing, though flat would obviously not do anything.

The question: how should work %TypedArray%.prototype.groupBy?

I think what you're hinting at is what the values would be in the return object? In a normal array.groupBy(), we'd receive { [key: string]: T[] } (arrays of the items). We might want to return the TypedArray and populate it with the items instead of a plain array?

zloirock commented 3 years ago

I mean that since the length of typed arrays is a constant, we can't use the same logic for returning object with typed arrays.

jridgewell commented 3 years ago

we can't use the same logic for returning object with typed arrays

Correct, but the spec text can change to support it. I wrote the spec the way I would write the JS, but it may be more appropriate to use a list of { key, list } structs internally, and transform that into the output object and array/typedarray.