Browse Learn Clojure Foundations as a Java Developer

Practical Immutability Examples

Practice immutable Clojure updates with collection transformations, application state transitions, and refactoring examples that move Java-style mutation into explicit value changes.

Immutability becomes real when you stop thinking “how do I change this object?” and start thinking “what new value should this function produce?”

Here is the basic shape you will use constantly:

1(def order {:id 1 :status :new :items [{:sku "A" :qty 1}]})
2
3(update order :status (constantly :paid))

What to focus on

  • Prefer update, assoc, dissoc for shallow changes.
  • Use update-in / assoc-in for nested structures.
  • Keep transformations pure so they are easy to test and reuse.

Java mental model: instead of “mutate a DTO”, treat state changes like producing a new immutable DTO (but without boilerplate constructors and setters).

In this section

Revised on Saturday, May 23, 2026