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
Replay: real traced execution (multi-file project)
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);
}
scores ← [88, 91, 72]
1void main() {2 var scores = [88, 91, 72];3 var allPassing = scores.every((score) => score >= 80);values this step[88, 91, 72]scoresallPassing ← false, stopAt ← 72 fails >= 80
2var scores = [88, 91, 72];3var allPassing = scores.every((score) => score >= 80);4var anyHigh = scores.any((score) => score >= 90);values this stepfalseallPassing72 fails >= 80stopAtanyHigh ← true, stopAt ← 91 passes >= 90
3var allPassing = scores.every((score) => score >= 80);4var anyHigh = scores.any((score) => score >= 90);5var summary = 'all=$allPassing high=$anyHigh';values this steptrueanyHigh91 passes >= 90stopAtsummary ← all=false high=true
4var anyHigh = scores.any((score) => score >= 90);5var summary = 'all=$allPassing high=$anyHigh';6print(summary);values this stepall=false high=truesummaryprint(summary);
5 var summary = 'all=$allPassing high=$anyHigh';6 print(summary);7}outputall=false high=truevalues this stepall=false high=truesummary
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.