Data Pipeline Patterns
Filter Scores
Filtering keeps values that match a rule and drops the rest before the next stage.
Program
Play the program to keep names whose score reaches the selected minimum.
filter_scores.dart
void main() {
var scores = {'Ada': 92, 'Linus': 78, 'Grace': 86};
var minScore = ;
var passed = <String>[];
for (var entry in scores.entries) {
if (entry.value >= minScore) {
passed.add(entry.key);
}
}
print('passed=${passed.join(",")}');
}
void main() {
var scores = {'Ada': 92, 'Linus': 78, 'Grace': 86};
var minScore = ;
var passed = <String>[];
for (var entry in scores.entries) {
if (entry.value >= minScore) {
passed.add(entry.key);
}
}
print('passed=${passed.join(",")}');
}
entries
`scores.entries` visits each key/value pair in a map.
filter
The `if` statement decides whether the current entry continues.
join
`passed.join(',')` turns the kept names into display text.