Data Pipeline Patterns
Any and Every
Iterable.every(test) returns true only when test(e) is true for every element; it stops as soon as it sees the first false. Iterable.any(test) returns true as soon as test(e) is true for any element; it stops on the first hit. Both are boolean reductions that short-circuit, and neither modifies the source list. They are the predicate siblings of where and fold.
Program
Play the program to check whether every score is at least 80 and whether any score is at least 90.
any_every.dart
void main() {
var scores = [88, 91, 72];
var allPassing = scores.every((score) => score >= 80);
var anyHigh = scores.any((score) => score >= 90);
var summary = 'all=$allPassing high=$anyHigh';
print(summary);
}
every
`list.every(test)` returns `true` only when every element passes `test`. It short-circuits on the first `false`; here `72 >= 80` fails, so the answer is `false`.
any
`list.any(test)` returns `true` as soon as one element passes `test`. It short-circuits on the first match; here `91 >= 90` succeeds, so the answer is `true`.
non-mutating
Both calls return a fresh `bool` and leave the source list untouched. They pair well with `where`/`fold` when a full result list is not needed.