Fork me on GitHub
#clojure-spec
<
2021-06-22
>
Michael Stokley18:06:50

ran into a surprise with s/or just now

Michael Stokley18:06:52

;; `s/or` destructures the value that the second pred sees
(let [spec (s/and (s/or :even even? :small #(> 10 %))
                  #(= 5 %))]
  (s/explain-str spec 5))
;; => "[:small 5] - failed: (= 5 %)\n"

;; flipped order of arguments to `s/and
(let [spec (s/and #(= 5 %)
                  (s/or :even even? :small #(> 10 %)))]
  (s/explain-str spec 5))
;; => "Success!\n"

Michael Stokley18:06:34

is there a way to avoid this?

Michael Stokley18:06:24

ah, i guess it's in the docstring of s/and

👍 2
Alex Miller (Clojure team)18:06:03

spec 2 has a non-flowing s/and variant to cover this