Spec’ing Maps (Again)

That brings us back to writing specs for maps. Recall that we passed over the strangeness that while the keywords in our actual book maps were sans namespaces (:title, for example), in the spec we used keywords with a namespace (:inventory.core/title, for example).

The reason for this is both clever and useful, two things that don’t always go together. When you specify the keys to a map, clojure.spec will try to look up the (fully qualified) keys in the registry. If it doesn’t find a spec registered under that key, no problem. But if it does, it validates the value associated with that key in the map against the spec.

Since up to now we haven’t registered specs under :inventory.core/title, :inventory. core/author, or

Get Getting Clojure 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.