reduce method

Emitter<T> reduce(
  1. T combine(
    1. T previous,
    2. T element
    ),
  2. List<Object?>? args, {
  3. String? name,
  4. bool keepAlive = false,
})

Set args to some unique value if creator is used on the fly, or null if the creator defined in a stable variable. See CreatorBase.args.

Implementation

Emitter<T> reduce(
    T Function(T previous, T element) combine, List<Object?>? args,
    {String? name, bool keepAlive = false}) {
  return Emitter<T>((ref, emit) async {
    final previous = ref.readSelf();
    final element = await ref.watch(this);
    emit(previous == null ? element : combine(previous, element));
  },
      name: name ?? argsName(args) ?? '${infoName}_reduce',
      keepAlive: keepAlive,
      args: args);
}