Skip to content

groupBy

groupBy<T, Keys>(iterable, keysOf, comparisonStrategy?): GroupedBy<T, Keys>

Defined in: group/group-by.ts:43

Groups the items of an iterable by the key returned from each accessor, one nested Map level per accessor.

Groups are created in the order their keys first occur. Time complexity: O(n · k) for k accessors, O(n) additional space, under the default "sameValueZero".

keysOf is an array rather than a rest parameter because a trailing comparisonStrategy is itself allowed to be a function, so it could not be told apart from one more accessor.

T

Keys extends readonly [unknown, unknown]

Iterable<T>

The input iterable.

{ [I in string | number | symbol]: Callable<[T], Keys[I]> }

One or more functions taking an item and returning a group key, outermost level first.

EqualityComparisonStrategy<Keys[number], Keys[number]> = "sameValueZero"

How keys are compared. Only "sameValueZero" is supported, because grouping is backed by a Map, whose key equality is fixed; any other strategy would need a different backing structure and a different complexity.

GroupedBy<T, Keys>

Nested maps from each group key to the items in that group.

If comparisonStrategy is not "sameValueZero".