Эта страница ещё не переведена, поэтому показана на английском. Помогите с переводом

atLeast · atMost

"Are there at least n?" — answered by stopping at the nth match instead of counting everything.

bool fxAtLeast<A>(int n, bool Function(A a) f, Iterable<A> iterable) bool fxAtMost<A>(int n, bool Function(A a) f, Iterable<A> iterable) Future<bool> fxAtLeastAsync<A>(int n, FutureOr<bool> Function(A a) f, FxAsyncIterable<A> iterable) Future<bool> fxAtMostAsync<A>(int n, FutureOr<bool> Function(A a) f, FxAsyncIterable<A> iterable) bool Fx<T>.atLeast(int n, bool Function(T a) f) // chain (sync) bool Fx<T>.atMost(int n, bool Function(T a) f) // chain (sync) Future<bool> FxAsync<T>.atLeast(int n, FutureOr<bool> Function(T a) f) // chain (async) Future<bool> FxAsync<T>.atMost(int n, FutureOr<bool> Function(T a) f) // chain (async)

Lecture

countWhere(f) >= 2 reads well and walks the whole input, even when the second match is the second element. atLeast(n, f) asks the same question and stops at the nth match; atMost(n, f) stops at the n + 1th, which is the moment its answer becomes false. On a long or lazy input — a range, a mapped pipeline, a stream of rows — the rest is never pulled.

They extend the quantifiers you already have. atLeast(1, f) is any and atMost(0, f) is none; the edges are defined so that holds — atLeast with n <= 0 is true and atMost with a negative n is false, both without reading anything. The async forms cancel upstream at the deciding match, like any. fxdart extension (not part of FxTS).

Demo 1 · Stop at the nth match

Demo 2 · atMost, the edges, async

Try it yourself

Exercise: decide the vote without counting every ballot.

Related: any — atLeast(1, f) · every — the universal quantifier · countWhere — when you need the exact count