Browse Clojure Foundations for Java Developers

Replacing Loops with Recursion

When a loop becomes a reduce, and when a recursive definition is actually clearer.

Sometimes recursion is the cleanest way to express an algorithm. But in everyday Clojure, many Java loops map better to higher-order functions (map, filter, reduce) than to explicit recursion.

A practical translation strategy

  1. If the loop transforms each element independently, start with map.
  2. If the loop selects elements, start with filter.
  3. If the loop accumulates a result, start with reduce.
  4. If none of those fit cleanly, consider loop/recur or recursion over the problem shape.

Java mental model: the goal is to eliminate index management and mutable accumulators, not to force recursion everywhere.

This section helps you pick the simplest shape that preserves the intent of the original loop.

In this section

Revised on Friday, April 24, 2026