switchLatest<T> method Null safety

Stream<T> switchLatest<T>(
  1. Stream<Stream<T>> streams

Convert a Stream that emits Streams (aka a 'Higher Order Stream') into a single Stream that emits the items emitted by the most-recently-emitted of those Streams.

This Stream will unsubscribe from the previously-emitted Stream when a new Stream is emitted from the source Stream and subscribe to the new Stream.


final switchLatestStream = SwitchLatestStream<String>(
    Rx.timer('A', Duration(seconds: 2)),
    Rx.timer('B', Duration(seconds: 1)),

// Since the first two Streams do not emit data for 1-2 seconds, and the
// 3rd Stream will be emitted before that time, only data from the 3rd
// Stream will be emitted to the listener.
switchLatestStream.listen(print); // prints 'C'


static Stream<T> switchLatest<T>(Stream<Stream<T>> streams) =>