Fork me on GitHub
#clojure-spec
<
2021-12-10
>
Zach Mitchell, PhD20:12:56

I'm trying to represent a piece of data of the form [:some-keyword int int] where the two ints should not be equal. Is there a way to encode this relationship between the two ints in a spec? Should the spec just encode the shape of the data and leave validating this relationship to something else?

Alex Miller (Clojure team)20:12:44

specs can be any predicate so the answer to all such questions is generally yes :)

Alex Miller (Clojure team)20:12:09

one option is to combine a first structural spec with a second value checking one with s/and

Alex Miller (Clojure team)20:12:28

s/and flows conformed values so that can provide structure for the second one

Alex Miller (Clojure team)20:12:18

(s/and (s/cat :k keyword? :a int? :b int?) #(not= (:a %) (:b %))) something like that

Zach Mitchell, PhD20:12:46

Excellent! Thank you