withLatestFrom4<A, B, C, D, R> method

Observable<R> withLatestFrom4 <A, B, C, D, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, Stream<D> latestFromStream4, R fn(T t, A a, B b, C c, D d))

Creates an Observable that emits when the source stream emits, combining the latest values from the five streams using the provided function.

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

Interactive marble diagram

Example

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

Implementation

Observable<R> withLatestFrom4<A, B, C, D, R>(
  Stream<A> latestFromStream1,
  Stream<B> latestFromStream2,
  Stream<C> latestFromStream3,
  Stream<D> latestFromStream4,
  R fn(T t, A a, B b, C c, D d),
) =>
    transform(WithLatestFromStreamTransformer.with4(
      latestFromStream1,
      latestFromStream2,
      latestFromStream3,
      latestFromStream4,
      fn,
    ));