Future<S> fold<S>(S initialValue, S combine(S previous, T element))

Reduces a sequence of values by repeatedly applying combine.

Source

Future<S> fold<S>(S initialValue, S combine(S previous, T element)) {
  _Future<S> result = new _Future<S>();
  S value = initialValue;
  StreamSubscription subscription;
  subscription = this.listen((T element) {
    _runUserCode(() => combine(value, element), (S newValue) {
      value = newValue;
    }, _cancelAndErrorClosure(subscription, result));
  }, onError: (e, st) {
    result._completeError(e, st);
  }, onDone: () {
    result._complete(value);
  }, cancelOnError: true);
  return result;
}