This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-05
Channels
- # announcements (2)
- # babashka (9)
- # bangalore-clj (4)
- # beginners (20)
- # calva (5)
- # cider (1)
- # clara (2)
- # clojure (11)
- # clojure-italy (2)
- # clojure-spec (11)
- # clojure-uk (4)
- # clojurescript (34)
- # clojutre (7)
- # code-reviews (5)
- # cursive (3)
- # datascript (7)
- # fulcro (7)
- # graalvm (8)
- # jackdaw (1)
- # malli (1)
- # nrepl (4)
- # off-topic (225)
- # reagent (23)
- # reitit (14)
- # remote-jobs (1)
- # ring-swagger (1)
- # shadow-cljs (19)
- # tools-deps (10)
Seems there's an inconsistency about how conforming works if you have qualified or unqualified s/keys
. Given specs:
(s/def ::a (s/conformer str))
(s/def ::b (s/keys :req []))
(s/def ::a1 (s/merge (s/keys :req-un [::a]) ::b))
(s/def ::a2 (s/merge (s/keys :req [::a]) ::b))
You get:
(s/conform ::a1 {:a 1})
=> {:a 1}
(s/conform ::a2 {::a 1})
=> #:clj-rest-client.core{:a "1"}
Weird.@roklenarcic Interesting. I tried it with the latest Spec 2 and it's the same. Also the same behavior using s/schema
(with [::a]
for qualified keys and {:a ::a}
for unqualified keys).
I think the reason is that clojure.spec.alpha/merge separately conforms each merged spec, then merges the results, so the unconformed value from the lateer overrides the result
Merge only confirms the last spec
Second works because all namespaced are always confirmed, even if they are part of the spec.
Ah yeah. That makes sense!
How? Makes no sense at all to me that it matters whether I use namespaced keys or not.
Alex says that merge only conforms the last spec, but if I s/merge
multiple s/keys
specs that use conformers and that use namespaced keys, all the keys are conformed not just the ones from the last merge argument