distinct method

ReactiveSubject<T> distinct([
  1. bool equals(
    1. T previous,
    2. T next
    )?
])

Emits all items emitted by the source ReactiveSubject that are distinct from their immediate predecessors.

Usage:

final subject = ReactiveSubject<int>();
final distinct = subject.distinct();
distinct.stream.listen(print);
subject.add(1); // Prints: 1
subject.add(1);
subject.add(2); // Prints: 2

Implementation

ReactiveSubject<T> distinct([bool Function(T previous, T next)? equals]) {
  final result = ReactiveSubject<T>();
  stream.distinct(equals).listen(result.add, onError: result.addError);
  return result;
}