MCPcopy Create free account
hub / github.com/denoland/std / groupBy

Method groupBy

data_structures/unstable_multimap.ts:775–790  ·  view source on GitHub ↗

* Groups items from an iterable by the result of `keyFn`, returning a new * multimap. Mirrors the shape of * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy | `Map.groupBy`, * but returns a code MultiMap so further mutation is supp

(
    items: Iterable<T>,
    keyFn: (item: T, index: number) => K,
  )

Source from the content-addressed store, hash-verified

773 * ```
774 */
775 static groupBy<K, T>(
776 items: Iterable<T>,
777 keyFn: (item: T, index: number) => K,
778 ): MultiMap<K, T> {
779 if (typeof keyFn !== "function") {
780 throw new TypeError(
781 `Cannot call MultiMap.groupBy: "keyFn" is not a function: received ${typeof keyFn}`,
782 );
783 }
784 const map = new MultiMap<K, T>();
785 let index = 0;
786 for (const item of items) {
787 map.add(keyFn(item, index++), item);
788 }
789 return map;
790 }
791}

Callers 7

shuffle_test.tsFile · 0.80
seeded_test.tsFile · 0.80
sample_test.tsFile · 0.80
applyInlineUpdatesFunction · 0.80
updateSnapshotsFunction · 0.80

Calls 1

addMethod · 0.95

Tested by

no test coverage detected