Data Pipeline Patterns
Reduce Totals
Reduction combines many values into a single result.
Reduce Totals
reduce_totals.py
amounts = [12, 8, 15]
include_shipping =
total = 0
for amount in amounts:
total += amount
if include_shipping:
total += 5
print(f"total={total}")
amounts = [12, 8, 15]
include_shipping =
total = 0
for amount in amounts:
total += amount
if include_shipping:
total += 5
print(f"total={total}")
reducing values
A reduce stage carries an accumulator forward as it visits each value.