Browse Clojure Foundations for Java Developers

Passing Functions as Arguments

How map/filter/reduce take behavior as an argument and make loops disappear.

Passing a function as an argument is the core move behind Clojure’s collection programming style. Instead of writing an index-based loop, you describe the transformation and supply the behavior that varies.

1(map inc [1 2 3])         ;; => (2 3 4)
2(filter even? [1 2 3 4])  ;; => (2 4)

What to focus on

  • The function you pass in is usually small and pure.
  • Many of these operations return lazy sequences; you realize work when you consume the result.
  • Named functions are often clearer than large anonymous functions.

Java mental model: similar to Streams, but you can do this with any seq-able data structure, and the pipeline reads like ordinary function calls.

The goal of this section is to make “function as argument” feel like the default tool for data transformation.

In this section

Revised on Friday, April 24, 2026