BACK
ReferencegroupBy
Reference · 68

groupBy

Splits the stream into groups by key.

Signature

groupBy(keySelector: (value: T) => K): OperatorFunction>

What it does

Emits a GroupedObservable for each new key. Each grouped$ contains only its key's values and has a key property.

When to use

Grouping events by userId/type/status, processing channels separately within one shared stream.

Gotcha

Each group lives until the source completes or its duration ends. On infinite streams with no duration, the number of groups can grow unbounded.

See also

mergeMap, toArray

script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...