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

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