Эта страница ещё не переведена, поэтому показана на английском. Помогите с переводом

groupsBy

Live groups as they open: a key and an inner stream of every later value that shares it.

class GroupedEvents<K, T> { final K key; final FxEvents<T> events; } FxEvents<GroupedEvents<K, T>> FxEvents<T>.groupsBy<K>(K Function(T value) keyOf, {Stream<void> Function(K key)? lastFor}) // chain (events)

Lecture

The pull layer's groupBy is a terminal: it pulls everything and hands you a Map. groupsBy is the live version. The first value of each key emits a GroupedEvents — a record of that key and an inner events stream — and every later value with the same key is forwarded to that inner. Groups appear in first-seen key order, as they open, not after the source has closed.

That is the same nested-FxEvents idea as window*, keyed by value instead of by time. A widget can subscribe to one group's inner the moment it appears and see later values as they arrive; it does not have to wait for a batch.

If lastFor is set, the first event (or completion) of lastFor(key) completes that group. A later value with the same key opens a new one — an idle timeout per user, a "session ended" signal per room. Without lastFor, groups stay open until the source completes (or errors, which errors every live group then the outer).

Cancelling the outer completes live groups silently, the same RxJS 9 rule the window family follows. fxdart events layer, after Rx's groupBy.

Demo 1 · Groups as they open

Demo 2 · lastFor closing a group

Try it yourself

Exercise: group SKUs by department prefix.

Related: groupBy — the same grouping as a keyed Map, on the pull layer · groupedBy — pull-layer groups as chainable (key, items) records · window* — live inners rotated by count, trigger, or clock