zip<T, R> static method

Stream<R> zip<T, R>(
  1. Iterable<Stream<T>> streams,
  2. R zipper(
    1. List<T> values
    )
)

Merges the iterable streams into one stream sequence using the given zipper function whenever all of the stream sequences have produced an element at a corresponding index.

It applies this function in strict sequence, so the first item emitted by the new Stream will be the result of the function applied to the first item emitted by Stream #1 and the first item emitted by Stream #2; the second item emitted by the new ZipStream will be the result of the function applied to the second item emitted by Stream #1 and the second item emitted by Stream #2; and so forth. It will only emit as many items as the number of items emitted by the source Stream that emits the fewest items.

If the provided streams is empty, the resulting sequence completes immediately without emitting any items and without any calls to the zipper function.

Interactive marble diagram

Example

Rx.zip(
  [
    Stream.value('Hi '),
    Stream.fromIterable(['Friend', 'Dropped']),
  ],
  (values) => values.first + values.last
)
.listen(print); // prints 'Hi Friend'

Implementation

static Stream<R> zip<T, R>(
        Iterable<Stream<T>> streams, R Function(List<T> values) zipper) =>
    ZipStream(streams, zipper);