This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-22
Channels
- # announcements (3)
- # babashka (6)
- # beginners (29)
- # calva (10)
- # cider (14)
- # clj-kondo (67)
- # cljfx (6)
- # clojure (34)
- # clojure-australia (1)
- # clojure-europe (46)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-spec (6)
- # clojure-uk (27)
- # clojured (1)
- # clojurescript (26)
- # conjure (14)
- # cursive (5)
- # data-science (1)
- # datomic (26)
- # deps-new (10)
- # editors (1)
- # events (2)
- # fulcro (23)
- # graalvm (41)
- # honeysql (5)
- # introduce-yourself (1)
- # jobs (1)
- # jobs-discuss (1)
- # luminus (2)
- # malli (22)
- # meander (5)
- # observability (3)
- # podcasts-discuss (1)
- # rdf (3)
- # re-frame (27)
- # remote-jobs (7)
- # reveal (6)
- # shadow-cljs (45)
- # xtdb (8)
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?
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
🙌 2
spec 2 has a non-flowing s/and variant to cover this