atLeast · atMost
"Are there at least n?" — answered by stopping at the nth match instead of counting everything.
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.
any — atLeast(1, f) ·
every — the universal quantifier ·
countWhere — when you need the exact count