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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access