API · Aggregate
sortedGroupBy()
Group adjacent equal keys while retaining only the current group.
Signature
sortedGroupBy<K>(
selector: ((value: T, context: C) => K) | keyof T,
): Exstream<{ key: K; values: T[] }, AggregateContext<{ key: K; values: T[] }, C>> Example
const runs = exstream(rowsSortedByCustomer).sortedGroupBy('customerId') Parameters
selectorSynchronous key callback or dot/bracket field path. Although the declaration accepts any property key, the runtime field shorthand recognizes strings only; use a callback for number or symbol fields.
Ordering contract
Input must already place equal keys contiguously. Keys compare with strict equality: objects by identity, NaN forms a new group each time, and 0 equals -0. The operator does not verify global sort order; a key appearing in separate runs produces separate output groups.
A group is emitted when the key changes or input ends. Memory is proportional to the largest adjacent group, not the whole stream, and downstream pressure propagates between groups. Values and contexts inside each group retain input order; output receives an aggregate context.
Errors
Selector failures become contextual record errors. Existing errors pass through without flushing or changing the active group. Promise keys are not awaited.
Forms
stream.sortedGroupBy('customerId')
exstream.pipeline().sortedGroupBy('customerId')
exstream.sortedGroupBy('customerId', stream)
stream.through(exstream.sortedGroupBy('customerId'))