This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-13
Channels
- # announcements (34)
- # aws (1)
- # beginners (99)
- # boot (19)
- # calva (26)
- # cider (24)
- # cljdoc (8)
- # cljs-dev (29)
- # clojure (107)
- # clojure-dev (3)
- # clojure-europe (12)
- # clojure-finland (1)
- # clojure-italy (24)
- # clojure-nl (5)
- # clojure-spec (13)
- # clojure-sweden (3)
- # clojure-uk (36)
- # clojurescript (4)
- # community-development (14)
- # cursive (3)
- # data-science (6)
- # datascript (57)
- # figwheel-main (3)
- # fulcro (9)
- # graalvm (11)
- # hoplon (18)
- # jobs (1)
- # jobs-discuss (2)
- # joker (10)
- # leiningen (13)
- # off-topic (23)
- # other-languages (1)
- # pathom (24)
- # pedestal (5)
- # re-frame (6)
- # reagent (45)
- # reitit (3)
- # rewrite-clj (1)
- # spacemacs (2)
- # sql (23)
- # tools-deps (6)
- # vim (5)
I have a bunch of specs that are quite repetitive to write out manually. Is there an easy way to define spec (e.g. w/in the current ns) with a function?
Essentially I have a map that looks something like:
{:event :some-kw
:metadata {:a 1 :b 2}}
where the spec of :metadata
depends on the value of :event
, which I want to check with specSo I think I could do something like:
(s/def :event1/event ...)
(s/def :event2/event ...)
;; and so on
(s/def :event1/metadata ...)
(s/def :event2/metadata ...)
;; and so on
(s/def :event1/message (s/keys :req-un [:event1/event :event1/metadata]))
(s/def :event2/message (s/keys :req-un [:event2/event :event2/metadata]))
;; etc
(s/def ::message (s/or :event1/message :event2/message ...))
But this seems extremely inelegant. Feels like I’m missing something obvious but I’m not sure whatSounds like a good use case for a multispec.
Yes, also repetitive code can be made less repetitive with a macro
> One common occurrence in Clojure is to use maps as tagged entities and a special field that indicates the “type” of the map where type indicates a potentially open set of types, often with shared attributes across the types. yes it does 🙂 thank you, @codonnell
does anybody know if there's a workaround for this issue https://dev.clojure.org/jira/browse/CLJ-2482
The linked issue in the comments has some patches people have been using.
Patches to Clojure that is
I’m not sure which of the many approaches on there is really the best
But we will definitely take a look at it in 1.11