clojure-spec 2021-12-10

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) 2021-12-10T20:22:44.242600Z

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

Alex Miller (Clojure team) 2021-12-10T20:23:09.243200Z

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

Alex Miller (Clojure team) 2021-12-10T20:23:28.243700Z

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

Alex Miller (Clojure team) 2021-12-10T20:24:18.244400Z

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

Excellent! Thank you