combine & CombineSpec
One combinator for "who triggers" and "who must have spoken" — plus zipAll and withLatestFromAll.
Lecture
combineLatest,
withLatestFrom and
zip differ in who may fire
an emit and whether every side must have spoken.
combine is the unified form: a list of
CombineSpec, each a source plus two
flags. It is a top-level function, not
FxEvents.combine — Dart cannot add statics to
FxEvents from another file.
causesEmit: true (the default) means an event from
this source may produce an output, once every
requireFirst spec has a value. All-true specs are
FxEvents.combineLatestAll.
causesEmit: false means this source is context only:
it updates the slot but never fires an emit on its own — that is
withLatestFrom.
requireFirst: true (the default) withholds every emit
until this source has produced at least one value;
false lets the slot be null until it
speaks. The result closes when every source has closed.
Two more combinators live next to it.
zipAll on
FxEvents<Stream<T>> collects every inner
stream until the outer completes, then zips them by index — inners
are not even subscribed until then.
withLatestFromAll is the N-ary
withLatestFrom: on every source event, combine it
with the latest of every other, dropping source events that arrive
before every other has spoken. fxdart events layer, after Rx's
combineLatest / withLatestFrom /
zipAll.
Demo 1 · Both sides trigger
Demo 2 · Context only — causesEmit: false
Try it yourself
Exercise: zipAll on a stream of streams, and withLatestFromAll on a source.
combineLatest — both sides trigger, the all-true CombineSpec ·
withLatestFrom — one-sided, the causesEmit: false spec ·
waitAll — zip, combineLatestAll, concat