This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-11
Channels
- # aleph (38)
- # announcements (6)
- # aws (1)
- # beginners (47)
- # calva (21)
- # cider (47)
- # cljs-dev (18)
- # clojure (40)
- # clojure-europe (7)
- # clojure-india (2)
- # clojure-italy (9)
- # clojure-nl (11)
- # clojure-norway (2)
- # clojure-sanfrancisco (1)
- # clojure-spec (17)
- # clojure-sweden (2)
- # clojure-uk (73)
- # clojurescript (10)
- # cursive (6)
- # datascript (12)
- # datavis (2)
- # defnpodcast (1)
- # duct (5)
- # emacs (36)
- # figwheel (2)
- # figwheel-main (10)
- # juxt (12)
- # leiningen (1)
- # midje (1)
- # nrepl (9)
- # off-topic (25)
- # pedestal (3)
- # portkey (3)
- # quil (2)
- # re-frame (45)
- # reagent (1)
- # ring (3)
- # ring-swagger (36)
- # rum (1)
- # shadow-cljs (48)
- # spacemacs (1)
- # speculative (50)
- # testing (2)
- # tools-deps (27)
- # yada (4)
how can I create a spec for a map like
{"2018-01-01": {:value 10}, "2018-03-22: {:value 20}}
write a function that decides whether that is a valid string - that function is your predicate
(s/def ::date valid-date?)
(s/def ::value int?)
(s/def ::data (s/keys :req-un [::value]))
(s/def ::m (map-of ::date ::data))
with a pred, the keys will will just conform to themselves, so that’s just making it slower
@alexmiller in what cases would conform-keys be needed?
cases where the keys need to be conformed
most maps have keys that are strings, numbers, keywords, uuids, etc - all of which conform to themselves, so there is no reason to conform the map keys
but if you had a map whose keys conformed to a value other than themselves (a regex spec, an s/or, a nested map, etc) then you would want to consider it
but even in that case, you have to think carefully to make sure the conformed values don’t create a case where two map keys have the same conformed value. if so, they will collide in the conformed map.