ran into a surprise with s/or
just now
;; `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"
is there a way to avoid this?
ah, i guess it's in the docstring of s/and
I believe itโs more of s/and
โs behavior as it โflowsโ values through (see https://github.com/clojure/spec-alpha2/wiki/Differences-from-spec.alpha#nonflowing-sand--new) You can try https://clojuredocs.org/clojure.spec.alpha/nonconforming
spec 2 has a non-flowing s/and variant to cover this