scan<R> method
Applies an accumulator function over the source ReactiveSubject, and returns each intermediate result as a ReactiveSubject.
Usage:
final subject = ReactiveSubject<int>(initialValue: 1);
final sum = subject.scan<int>(0, (accumulated, current, index) => accumulated + current);
sum.stream.listen(print); // Prints: 1
subject.add(2); // Prints: 3
subject.add(3); // Prints: 6
Implementation
ReactiveSubject<R> scan<R>(R initialValue,
R Function(R accumulated, T current, int index) accumulator) {
final result = ReactiveSubject<R>();
stream
.scan(accumulator, initialValue)
.listen(result.add, onError: result.addError);
return result;
}