Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

combineLatest

On every event from either side, emits combine of the two latest values — once both sides have spoken at least once.

FxEvents<R> FxEvents<T>.combineLatest<U, R>(Stream<U> other, R Function(T a, U b) combine) // chain (events)

Lecture

A form is valid when the current username and the current password both pass — two streams typed independently, one derived state that must be right after every keystroke on either. combineLatest(other, combine) is that shape: it remembers the latest value of each side, and every event from either stream re-runs combine on the fresh pair.

The rules, precisely. Nothing emits until both sides have produced at least one value — there is no half-initialized pair. After that, one event in produces exactly one event out. And a side that closes stops updating but its last value stays in play: the result only closes when both sides have closed.

Choose your combinator by who triggers. If updates from either side should re-derive the state, this is your operator. If only the source's events should fire — with the other stream merely consulted for its latest value — that is withLatestFrom. Contrast with the pull world's zip, which pairs the n-th with the n-th; combineLatest pairs newest with newest and never waits for indexes to line up. fxdart events layer, after Rx's operator of the same name.

Demo 1 · Form validation from two fields

Demo 2 · A closed side keeps its last word

Try it yourself

Exercise: one display state from two sensors.

Related: withLatestFrom — one-sided: only source events emit · zip — index-aligned pairing in the pull world · LiveValue — when what you need is the current value itself