本页尚未翻译,因此以英文显示。 参与翻译

every

True when every element satisfies a predicate — vacuously true for an empty iterable.

bool every<A>(bool Function(A a) f, Iterable<A> iterable) Future<bool> everyAsync<A>(FutureOr<bool> Function(A a) f, FxAsyncIterable<A> iterable) Future<bool> FxAsync.every(FutureOr<bool> Function(T a) f) // chain (async)

Lecture

every scans left to right and bails out — short-circuits — the instant it finds an element that fails the predicate, returning false right there without touching the rest of the iterable. If nothing fails (including the case where there's nothing at all), it returns true: an empty iterable vacuously satisfies "every element is X."

On the sync chain there's no dedicated Fx.every — it isn't needed, since Fx already inherits Dart's own Iterable.every, which has exactly this short-circuiting behavior. The async chain does define its own .every(), because it has to await each predicate call.

Demo 1 · Basics & short-circuiting

The peek counter stops at 3, not 4 — evaluation halts right at the first failure:

Demo 2 · Async

Try it yourself

Exercise: use every to check whether everyone passed (score >= 60).

Related: some — the "at least one" counterpart · filter — collect every match instead of a bool · find — get the first failing/matching element · predicates — ready-made predicates to pair with every