Fork me on GitHub
#clojure-spec
<
2022-02-09
>
Benjamin14:02:55

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)14:02:45

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

✔️ 1
Alex Miller (Clojure team)14:02:18

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

Alex Miller (Clojure team)14:02:48

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

Benjamin14:02:22

(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)15:02:16

why is ::special so special?

Alex Miller (Clojure team)15:02:24

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

☝️ 1
1
✔️ 1
Aron17:02:50

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 🙂