Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

any

True when at least one element satisfies a predicate — false for an empty iterable.

bool any<A>(bool Function(A a) f, Iterable<A> iterable) Future<bool> anyAsync<A>(FutureOr<bool> Function(A a) f, FxAsyncIterable<A> iterable) bool Fx.any(bool Function(T a) f) // chain (inherited from Iterable) Future<bool> FxAsync.any(FutureOr<bool> Function(T a) f) // chain bool some<A>(bool Function(A a) f, Iterable<A> iterable) // FxTS alias

Lecture

any is the Dart-idiomatic name; fxdart also accepts the FxTS spelling some — they're the same operator. It's every's mirror image: it scans left to right and short-circuits the moment it finds a match, returning true right away. If it never finds one — including on an empty iterable, which is the opposite vacuous case from every — it returns false only after checking everything.

On a sync chain, .any(f) comes straight from Dart's IterableFx inherits it — so it needs no special definition. The async chain and the data-first any(f, iterable) form are supplied by fxdart, and the FxTS spelling some still works in every position.

Demo 1 · Basics & short-circuiting

Demo 2 · Async

Try it yourself

Exercise: use any to check if anything in the cart costs more than 10.

Related: every — the "all of them" counterpart · includes — a specialization of any · find — get the matching element, not just a bool · predicates — ready-made predicates to pair with any