withLatestFromList method

Stream<List<T>> withLatestFromList(
  1. Iterable<Stream<T>> latestFromStreams
)

Creates a Stream that emits when the source stream emits, combining the latest values from the streams into a list. This is helpful when you need to combine a dynamic number of Streams.

If any of latestFromStreams has not emitted any values, this stream will not emit either.

Interactive marble diagram

Example

Stream.fromIterable([1, 2]).withLatestFromList(
    [
      Stream.fromIterable([2, 3]),
      Stream.fromIterable([3, 4]),
      Stream.fromIterable([4, 5]),
      Stream.fromIterable([5, 6]),
      Stream.fromIterable([6, 7]),
    ],
  ).listen(print); // print [2, 2, 3, 4, 5, 6] (due to the async nature of streams)

Implementation

Stream<List<T>> withLatestFromList(Iterable<Stream<T>> latestFromStreams) =>
    WithLatestFromStreamTransformer.withList<T>(latestFromStreams).bind(this);