scan<S> method

Stream<S> scan<S>(
  1. S seed,
  2. S accumulate(
    1. S acc,
    2. T value
    )
)

Accumulates state across events using seed and accumulate.

countStream.scan(0, (acc, n) => acc + n) // running total

Implementation

Stream<S> scan<S>(S seed, S Function(S acc, T value) accumulate) async* {
  var state = seed;
  await for (final value in this) {
    state = accumulate(state, value);
    yield state;
  }
}