any method

Future<bool> any(bool test(T element))

Checks whether test accepts any element provided by this stream.

Completes the Future when the answer is known.

If this stream reports an error, the Future reports that error.

Stops listening to the stream after the first matching element has been found.

Internally the method cancels its subscription after this element. This means that single-subscription (non-broadcast) streams are closed and cannot be reused after a call to this method.

Source

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

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-async/Stream/any.html