withLatestFrom<S, R> method

ReactiveSubject<R> withLatestFrom<S, R>(
  1. ReactiveSubject<S> other,
  2. R combiner(
    1. T event,
    2. S latestFromOther
    )
)

Combines the latest values of two ReactiveSubjects using a specified combiner function.

Usage:

final subject1 = ReactiveSubject<int>(initialValue: 1);
final subject2 = ReactiveSubject<String>(initialValue: 'a');
final combined = subject1.withLatestFrom(subject2, (int a, String b) => '$a$b');
combined.stream.listen(print); // Prints: 1a
subject1.add(2); // Prints: 2a

Implementation

ReactiveSubject<R> withLatestFrom<S, R>(ReactiveSubject<S> other,
    R Function(T event, S latestFromOther) combiner) {
  final result = ReactiveSubject<R>();
  stream
      .withLatestFrom(other.stream, combiner)
      .listen(result.add, onError: result.addError);
  return result;
}