feat: override groupBy to return Collection (#10791)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Danial Raza
2025-03-05 21:19:20 +01:00
committed by GitHub
parent b7e334e74a
commit e273afbb93
2 changed files with 37 additions and 0 deletions

View File

@@ -1088,6 +1088,17 @@ export class Collection<Key, Value> extends Map<Key, Value> {
return coll;
}
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy | Map.groupBy()}
* but returns a Collection instead of a Map.
*/
public static override groupBy<Key, Item>(
items: Iterable<Item>,
keySelector: (item: Item, index: number) => Key,
): Collection<Key, Item[]> {
return new this[Symbol.species]<Key, Item[]>(Map.groupBy(items, keySelector));
}
/**
* @internal
*/