Design patterns·Functional ideas that went mainstream
the loop with an accumulator and two conditions became three named steps, and the intermediate variable disappeared.
Map, filter, reduce
Also calledmap filter reduce, map filter fold, collection pipeline
The three operations that cover most of what an explicit loop over a collection was doing: transform each element, keep some of them, and combine them into one value. Naming the operation says the intent at a glance — a reader can tell a transformation from a filter without tracing the body — and it removes the index and accumulator variables that most off-by-one bugs live in. The honest limit is that a loop with early exit or several accumulators is usually clearer left as a loop.