combineLatest<T> static method

ReactiveSubject<List<T>> combineLatest<T>(
  1. List<ReactiveSubject<T>> subjects
)

Combines the latest values of multiple ReactiveSubjects into a single ReactiveSubject that emits a List of those values.

Usage:

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

Implementation

static ReactiveSubject<List<T>> combineLatest<T>(
    List<ReactiveSubject<T>> subjects) {
  final result = ReactiveSubject<List<T>>();
  Rx.combineLatestList(subjects.map((s) => s.stream))
      .listen(result.add, onError: result.addError);
  return result;
}