Modeling a Change

Recall that Clojure’s focus is on immutable values. With immutable data, an “update” produces a new instance of an entity (or collection of entities), rather than updating the entity or entities in place. In most cases, this will serve your purposes admirably. Occasionally, you’ll need to model the changes in the application’s world, to track changes in data. Specifically, you want to hold onto a reference to a set of data that changes.

In a multithreaded scenario, updating data in place introduces a lot of complex questions. Who can change the data? How do other threads get notified of the change? Which process wins when multiple simultaneous updates are happening? Clojure provides elegant answers to all of these questions ...

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.