Constructing Entities

Once you’ve defined an entity’s structure, you need to build functions that populate that structure. Most of the time, you populate your entities using defrecord’s positional and map factory functions, or the core library functions to create maps (like {}, hash-map, and zipmap).

However, some common situations deserve a bit more consideration. One of the most common situations is the case of entities with optional values. Clojure can deal with this in a number of ways, and we’ll look at some of the most common. We’ll also look at constructors that create derived values or have side effects.

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.