Question

Does nil conform to clojure.spec.alpha/keys spec? In other words, what does this return...?

(s/explain-data (s/keys) nil)

Answer

No, nil doesn't conform to keys, because keys is a map validating spec [^1], and nil is not a map.

This is what's returned

{:problems [{:path [], :pred map?, :via [], :val nil, :in []}],
 :value nil,
 :spec [clojure.spec.alpha$map_spec_impl$reify__1931
        1844810227
        "[email protected]"]} 

[^1]: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html#clojure.spec.alpha/keys
[^2]: "a bare (s/keys) is valid and will check all attributes of a map without checking which keys are required or optional." https://clojure.org/guides/spec#_entity_maps

Learn

Author

xavi

Reviews
Last
next

Students 0