Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:async
  3. Stream<T>
  4. every method
every
description

every method

Future<bool>every(
  1. booltest(
    1. Telement
    )
)

Checks whethertest accepts all elements provided by this stream.

Callstest on each element of this stream.If the call returnsfalse, the returned future is completed withfalseand processing stops.

If this stream ends without finding an element thattest rejects,the returned future is completed withtrue.

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

Example:

final result =    await Stream.periodic(const Duration(seconds: 1), (count) => count)        .take(15)        .every((x) => x <= 5);print(result); // false

Implementation

Future<bool> every(bool test(T element)) {  _Future<bool> future = _Future<bool>();  StreamSubscription<T> subscription = this.listen(    null,    onError: future._completeError,    onDone: () {      future._complete(true);    },    cancelOnError: true,  );  subscription.onData((T element) {    _runUserCode(() => test(element), (bool isMatch) {      if (!isMatch) {        _cancelAndValue(subscription, future, false);      }    }, _cancelAndErrorClosure(subscription, future));  });  return future;}
  1. Dart
  2. dart:async
  3. Stream<T>
  4. every method
Stream class

[8]ページ先頭

©2009-2025 Movatter.jp