every method Null safety

Future<bool> every (
  1. bool test(
    1. T element

Checks whether test accepts all elements provided by this stream.

Calls test on each element of this stream. If the call returns false, the returned future is completed with false and processing stops.

If this stream ends without finding an element that test rejects, the returned future is completed with true.

If this stream emits an error, or if the call to test throws, the returned future is completed with that error, and processing stops.


Future<bool> every(bool test(T element)) {
  _Future<bool> future = new _Future<bool>();
  StreamSubscription<T> subscription =
      this.listen(null, onError: future._completeError, onDone: () {
  }, cancelOnError: true);
  subscription.onData((T element) {
    _runUserCode(() => test(element), (bool isMatch) {
      if (!isMatch) {
        _cancelAndValue(subscription, future, false);
    }, _cancelAndErrorClosure(subscription, future));
  return future;