Browse Clojure Foundations for Java Developers

Understanding Pure Functions

What makes a function pure, why it matters, and how to spot hidden side effects.

A pure function always returns the same result for the same inputs, and it does not do anything observable besides returning a value. No I/O. No mutation. No reading the clock. No random numbers.

That sounds academic until you feel the payoff: pure functions are easy to test, easy to refactor, and safe to run concurrently.

How to think about it as a Java engineer

  • A pure function is closer to a “static utility method” than to a method that mutates an object graph.
  • The goal is not perfection. The goal is to keep most of your logic in a pure core, and keep side effects in a thin shell.
1(defn total [prices] (reduce + prices))  ;; pure

As you go through this section, practice reading code and asking: “what inputs does this depend on?” and “what does it change?” If the answer is “only its arguments” and “nothing”, you are looking at a pure function.

In this section

Revised on Friday, April 24, 2026