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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.