mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
feat: override groupBy to return Collection (#10791)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user