resolveAllReduced<R> method

FutureOr<T> resolveAllReduced<R>(
  1. T reducer(
    1. T value,
    2. T element
    )
)

Resolves all elements and reduce them with reducer.

Implementation

FutureOr<T> resolveAllReduced<R>(T Function(T value, T element) reducer) {
  var self = this;

  if (_isNotFuture(T) && self is Iterable<T>) {
    return self.reduce(reducer);
  }

  var all = allAsList;
  if (all.isEmpty) return <T>[].reduce(reducer);

  if (all.isAllResolved) {
    var l = all.cast<T>();
    return l.reduce(reducer);
  } else {
    return Future.wait(all.asFutures).resolveMapped((l) {
      return l.reduce(reducer);
    });
  }
}