Free practice · ordering · medium
Practice
Process a list safely
Order a simple workflow that calculates the mean of a non-empty list.
Collection-processing contract
A mean needs valid input, changing state, and one final division
- Input rule
- The list must contain at least one value
- Changing state
- total and count
- Per-item rule
- Add one value and increase count once
- Required output
- One mean after all items are visited
The trace should show why division is safe and how total and count stay synchronized as the list is processed.