withLatestFrom5<A, B, C, D, E, R> method

Stream<R> withLatestFrom5<A, B, C, D, E, R>(
  1. Stream<A> latestFromStream1,
  2. Stream<B> latestFromStream2,
  3. Stream<C> latestFromStream3,
  4. Stream<D> latestFromStream4,
  5. Stream<E> latestFromStream5,
  6. R fn(
    1. T t,
    2. A a,
    3. B b,
    4. C c,
    5. D d,
    6. E e
    )
)

Creates a Stream that emits when the source stream emits, combining the latest values from the six streams using the provided function.

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

Interactive marble diagram

Example

Stream.fromIterable([1, 2])
  .withLatestFrom5(
    Stream.fromIterable([2, 3]),
    Stream.fromIterable([3, 4]),
    Stream.fromIterable([4, 5]),
    Stream.fromIterable([5, 6]),
    Stream.fromIterable([6, 7]),
    (int a, int b, int c, int d, int e, int f) => a + b + c + d + e + f,
  )
  .listen(print); // prints 22 (due to the async nature of streams)

Implementation

Stream<R> withLatestFrom5<A, B, C, D, E, R>(
  Stream<A> latestFromStream1,
  Stream<B> latestFromStream2,
  Stream<C> latestFromStream3,
  Stream<D> latestFromStream4,
  Stream<E> latestFromStream5,
  R Function(T t, A a, B b, C c, D d, E e) fn,
) =>
    transform(WithLatestFromStreamTransformer.with5(
      latestFromStream1,
      latestFromStream2,
      latestFromStream3,
      latestFromStream4,
      latestFromStream5,
      fn,
    ));