MCPcopy
hub / github.com/immutable-js/immutable-js / groupByFactory

Function groupByFactory

src/Operations.js:384–395  ·  view source on GitHub ↗
(collection, grouper, context)

Source from the content-addressed store, hash-verified

382}
383
384export function groupByFactory(collection, grouper, context) {
385 const isKeyedIter = isKeyed(collection);
386 const groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
387 collection.__iterate((v, k) => {
388 groups.update(
389 grouper.call(context, v, k, collection),
390 (a) => ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a)
391 );
392 });
393 const coerce = collectionClass(collection);
394 return groups.map((arr) => reify(collection, coerce(arr))).asImmutable();
395}
396
397export function partitionFactory(collection, predicate, context) {
398 const isKeyedIter = isKeyed(collection);

Callers 1

groupByFunction · 0.90

Calls 12

isKeyedFunction · 0.90
isOrderedFunction · 0.90
OrderedMapClass · 0.90
MapClass · 0.90
collectionClassFunction · 0.85
reifyFunction · 0.85
asMutableMethod · 0.65
updateMethod · 0.65
pushMethod · 0.65
asImmutableMethod · 0.65
mapMethod · 0.65
__iterateMethod · 0.45

Tested by

no test coverage detected