This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-08
Channels
- # announcements (2)
- # babashka (100)
- # beginners (25)
- # biff (7)
- # calva (13)
- # cider (24)
- # clj-kondo (39)
- # cljsrn (2)
- # clojure (22)
- # clojure-dev (13)
- # clojure-europe (12)
- # clojure-gamedev (3)
- # clojure-losangeles (2)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-spec (11)
- # clojure-uk (2)
- # clojurescript (20)
- # core-async (8)
- # cursive (7)
- # data-science (2)
- # datomic (14)
- # emacs (6)
- # events (7)
- # fulcro (9)
- # honeysql (1)
- # kaocha (24)
- # lambdaisland (3)
- # leiningen (6)
- # lsp (30)
- # membrane (7)
- # missionary (10)
- # nbb (48)
- # nextjournal (13)
- # off-topic (6)
- # parinfer (4)
- # pathom (1)
- # polylith (1)
- # reagent (7)
- # rewrite-clj (6)
- # ring (11)
- # sci (7)
- # shadow-cljs (8)
- # sql (13)
How would I go about making a certain key necessary when that key can exist at different depths in a map (and it only needs to exist at least once)? Do I need to normalize the map and put it at one level or is there another way?
Use clojure.walk
to see if exists at least once?
(s/def ::guarantee-key-in-map (write-your-fn-here))
(s/def ::my-map
(s/and ::guarantee-key-in-map
(s/keys :req [:other-key
... and so on
something like that?
(s/valid? ::my-map some-map)
I don’t write that many specs, so don’t copy verbatim 😄 it probably doesn’t compile
Or simpler, without the map thing:
(s/def ::guarantee-key-in-map (write-your-fn-here))
(s/valid? ::guarantee-key-in-map some-map)
The key takeaway is that your spec is something separate from e.g. s/keys
. I don’t think you can use s/keys
to say arbitrary things about certain values in your map. But you can do so with a separate spec that you can s/and
Anybody, feel free to take the wheel and show @U02FM0NNZAB how I’m wrong 🙂