fold<R> method

Future<R> fold<R>(
  1. R initialValue,
  2. R reducer(
    1. R acc,
    2. T item
    )
)

Implementation

Future<R> fold<R>(R initialValue, R Function(R acc, T item) reducer) async {
  var acc = initialValue;

  while (!drained) {
    final resultFuture = pull();
    final result = resultFuture is Future ? await resultFuture : resultFuture;
    acc = result.p(O.fold(() => acc, (v) => reducer(acc, v)));
  }

  return acc;
}