This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-07
Channels
- # aleph (15)
- # beginners (186)
- # boot (11)
- # bristol-clojurians (1)
- # clara (1)
- # cljdoc (2)
- # cljs-dev (5)
- # clojure (57)
- # clojure-austin (1)
- # clojure-dev (87)
- # clojure-italy (7)
- # clojure-spec (5)
- # clojure-uk (56)
- # clojurescript (18)
- # cursive (29)
- # data-science (10)
- # datomic (84)
- # duct (83)
- # figwheel-main (4)
- # fulcro (42)
- # jobs (3)
- # lambdaisland (2)
- # off-topic (28)
- # parinfer (3)
- # portkey (3)
- # re-frame (28)
- # reitit (7)
- # remote-jobs (8)
- # shadow-cljs (29)
- # spacemacs (30)
- # specter (6)
- # sql (8)
- # tools-deps (60)
Not sure how to achieve something. If I want to check a map for :key
, but define the spec with ::some-type-of-key
(different spec name) in (s/keys :req-un [::key])
?
More concretely, I have a :type
key on multiple things, and the spec is slightly different for each.
You should probably use namespace-qualified keys in that case (that is :req
)
You can also use a level of indirection and define specs like this:
(s/def :a/type int?)
(s/def ::a-type (s/keys :req-un [:a/type]))
(s/def :b/type string?)
(s/def ::b-type (s/keys :req-un [:b/type]))
(def int {:type 10})
(def b {:type "number"})
(s/valid? ::a-type a)
;; => true
(s/valid? ::a-type b)
;; => false
(s/valid? ::b-type b)
;; => true
(s/valid? ::b-type a)
;; => false
Namespaced keys works, thanks
@alexmiller: I'm doing my first really rigorous spec of something with a lot of data, and this morning I'm on my 4th or 5th time understanding why a certain design decision makes more sense than I realized with either smaller data or less complete specs. It's pretty great to be using something with so much depth of thought and experience behind it!