Updating Collections

Our applications are in constant communication with the external world, receiving new information, updating existing information, and removing information that’s no longer relevant. However, this seems at odds with Clojure’s immutable core collections.

In Clojure, change is always modeled as the application of a pure function to an immutable value, resulting in a new immutable value. We’ll use the simple word update to describe this means of change so as to avoid linguistic gymnastics.

Defining collections with immutability has many advantages. First, concurrent threads can pass around values, rather than references to values. This ensures that data isn’t modified unpredictably by other threads. Second, we separate our ...

Get Clojure Applied now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.