groupBy<K> method Null safety

Stream<GroupedStream<T, K>> groupBy<K>(
  1. K grouper(
    1. T value
    ),
  2. {Stream<void> durationSelector(
    1. GroupedStream<T, K> grouped
    )?}
)

The GroupBy operator divides a Stream that emits items into a Stream that emits GroupedStream, each one of which emits some subset of the items from the original source Stream.

GroupedStream acts like a regular Stream, yet adding a 'key' property, which receives its Type and value from the grouper Function.

All items with the same key are emitted by the same GroupedStream.

Optionally, groupBy takes a second argument durationSelector. durationSelector is a function that returns an Stream to determine how long each group should exist. When the returned Stream emits its first data or done event, the group will be closed and removed.

Implementation

Stream<GroupedStream<T, K>> groupBy<K>(
  K Function(T value) grouper, {
  Stream<void> Function(GroupedStream<T, K> grouped)? durationSelector,
}) =>
    transform(GroupByStreamTransformer<T, K>(grouper,
        durationSelector: durationSelector));