Skip to content

Function: group()

group<T, G>(predicates, …sources): { [K in string | number | symbol]: GroupValue<T, G[K]>[] }

Splits the concatenated sources into one array per named predicate. Consumes the input once, routing each element to the FIRST predicate it satisfies (so groups are disjoint); elements matching no predicate are dropped. Type-guard predicates narrow their group’s element type (see GroupValue). predicates leads so the sources can stay variadic.

T

G extends GroupPredicates<T>

The map of group name -> predicate.

G

Named predicates; evaluated in declaration order.

…readonly Source<T>[]

Containers to concatenate (nullish sources are skipped).

{ [K in string | number | symbol]: GroupValue<T, G[K]>[] }

An object with the same keys, each an array of its group’s elements.

const { strings, fns } = group({ strings: isString, fns: isFunction }, xs);