Data Pipeline Patterns
Reduce Total
Reduction carries one accumulator through every input value.
Program
Play the program to sum amounts and optionally add shipping.
reduce_total.dart
void main() {
var amounts = [12, 8, 15];
var includeShipping = ;
var total = 0;
for (var amount in amounts) {
total += amount;
}
if (includeShipping) total += 5;
print('total=$total');
}
void main() {
var amounts = [12, 8, 15];
var includeShipping = ;
var total = 0;
for (var amount in amounts) {
total += amount;
}
if (includeShipping) total += 5;
print('total=$total');
}
accumulator
`total` stores the running result.
compound assignment
`total += amount` adds into the accumulator.
optional stage
The shipping branch is another small pipeline stage.