jargon

Comparison

Higher-order functionvsMap, filter, reduce

Higher-order function

the function's argument is another function, and what it actually does depends entirely on what you passed.

A function that takes or returns another function. It is the mechanism behind map, filter, sort comparators, decorators, middleware and retry helpers — anywhere the shape of a computation is fixed and one step of it is not. The pattern-catalogue equivalents are strategy and template method, both of which reduce to a higher-order function in a language with closures.

Full entry →

Map, filter, reduce

the loop with an accumulator and two conditions became three named steps, and the intermediate variable disappeared.

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.

Full entry →

Related comparisons