Browse Learn Clojure Foundations as a Java Developer

Passing Functions as Arguments in Clojure

Learn how Clojure APIs such as map, filter, reduce, sort-by, and custom helpers accept behavior as function arguments instead of forcing Java-style loop control.

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

  • Core Function Arguments in Clojure
    Learn how Clojure APIs like map, filter, and reduce take behavior as an argument, and how to choose between named functions, anonymous functions, and keyword functions.
  • Writing Custom Functions That Accept Functions
    Learn when it is worth writing your own function-taking functions in Clojure, how to design them cleanly, and how to avoid thin wrappers that add no value.
Revised on Saturday, May 23, 2026