Problem: I want to spec a coll of maps. I know I can use s/coll-of
and specify :kind vector?
or :kind list?
,
but either is fine, so I've omitted it. When I call s/explain
for this spec with a map it fails properly,
but I get explain data for each map entry that says "x" isn't a map. I'd prefer it say it's not a collection and stop there.
Solution:
(s/def ::example (s/coll-of (s/keys :req-un [::foo])
:kind sequential?))
(s/explain ::example {:foo 1 :bar 2})
=>
-- Spec failed --------------------
{:foo "bar", :baz 2}
should satisfy
sequential?
-------------------------
Detected 1 error
Why?:
(coll? {})
=> true
(sequential? {})
=> false