clojure-spec 2022-02-09

There is no way in keys to say "use this spec" like:

(s/def ::foo (s/keys :req [(::bar string?)]) )
something like this right? What is the most concise alternative?

Alex Miller (Clojure team) 2022-02-09T14:52:45.795489Z

you mean to specify an ad hoc spec for a key? no

✔️ 1
Alex Miller (Clojure team) 2022-02-09T14:53:18.503749Z

(s/def ::bar string?)
(s/def ::foo (s/keys :req [::bar]))

Alex Miller (Clojure team) 2022-02-09T14:53:48.314499Z

spec 2 has some facility for specifying ad hoc specs for unqualified keys in a schema

(s/def ::foo
  (fn [m]
    (and
     (s/valid? ::foo-default-keys (dissoc m ::special))
     (s/valid? ::foo-special-key (select-keys m  [::special])))))
if I do this my design is wrong I feel like

Alex Miller (Clojure team) 2022-02-09T15:00:16.535259Z

why is special so special?

Alex Miller (Clojure team) 2022-02-09T15:01:24.745269Z

I find things that are hard to spec often point to problems in the code/data design

✔️ 1
☝️ 1
1

Wouldn't this statement be true in general? What I mean is, when something is problematic it's not enough to know it's problem in "code/ data design" because it's not clear how to unproblem it 🙂