clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
2020-11-18T15:11:29.384400Z

I stumbled upon this behavior, which I found a bit weird.

(s/def :sequence-list/eid number?)
(s/valid?
 (s/keys :opt []) ;; ⇠ no reference to :sequence-list/eid
 (merge #:entity {:label "foo"}
        #:sequence-list {:eid "sample"}))
=> false
does the s/keys look at global registry in some way?

alexmiller 2020-11-18T15:11:48.384600Z

yes

alexmiller 2020-11-18T15:11:58.384900Z

s/keys will check all registered keys in the map

alexmiller 2020-11-18T15:12:21.385200Z

so even (s/keys) is a spec that does things

2020-11-18T15:13:05.385500Z

interesting, thanks 🙂

alexmiller 2020-11-18T15:13:46.386100Z

this is covered if you (doc s/keys) or look at the spec guide https://clojure.org/guides/spec

2020-11-18T15:13:48.386200Z

> > In addition, the values of all namespace-qualified keys will be validated > (and possibly destructured) by any registered specs. Note: there is > no support for inline value specification, by design.

alexmiller 2020-11-18T15:13:57.386600Z

^^

2020-11-18T15:13:58.386700Z

yeah says so in docstring 🙂