map<R> method

ReactiveSubject<R> map<R>(
  1. R mapper(
    1. T event
    )
)

Transforms the items emitted by the source ReactiveSubject by applying a function to each item.

Usage:

final subject = ReactiveSubject<int>(initialValue: 1);
final doubled = subject.map((i) => i * 2);
doubled.stream.listen(print); // Prints: 2
subject.add(2); // Prints: 4

Implementation

ReactiveSubject<R> map<R>(R Function(T event) mapper) {
  final result = ReactiveSubject<R>();
  stream.map(mapper).listen(result.add, onError: result.addError);
  return result;
}