This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-22
Channels
- # ai (1)
- # announcements (4)
- # babashka (23)
- # beginners (27)
- # biff (17)
- # calva (5)
- # clerk (6)
- # clj-commons (27)
- # clj-kondo (35)
- # clojars (12)
- # clojure (27)
- # clojure-denver (3)
- # clojure-europe (71)
- # clojure-norway (7)
- # clojure-spec (5)
- # clojure-uk (2)
- # clojurescript (45)
- # data-science (9)
- # datomic (4)
- # dev-tooling (2)
- # devcards (1)
- # hoplon (2)
- # hyperfiddle (36)
- # introduce-yourself (3)
- # malli (11)
- # missionary (2)
- # off-topic (63)
- # polylith (5)
- # rdf (2)
- # reagent (12)
- # schema (1)
- # shadow-cljs (11)
- # sql (6)
- # tools-deps (23)
- # xtdb (6)
In a map spec, can you refer to other specs unqualified? The doc only mentions qualified keys: https://github.com/metosin/malli#qualified-keys-in-a-map And just in general, how would I refer to another spec in Malli? Say I want to create an age spec which is a range from 1 to 120? For example? Or a email type for email and I want to then use that in lists and maps and all that?
Like say given this example:
(def Address
[:map
[:id string?]
[:tags [:set keyword?]]
[:address
[:map
[:street string?]
[:city string?]
[:zip int?]
[:lonlat [:tuple double? double?]]]]])
I want to make city an enum of say 500 cities, and I want to define that separately and refer it here? And I might refer it in other places, but I don't want the key to become ::city
The wiki seems to define everything inline.put it in a var or binding, just like any other data
(def City
[:enum "Ahmedabad" "Alexandria" ...])
(def Address
[:map
[:address
[:city City]]])
we do this even for widely-used schemas. We just put the var in a common schemas namespace
I guess that's a simple way. I also found you can use mutable registry and set default registry. I won't what the pros and cons are as opposed to what you suggested
@UK0810AQ2 Just making sure I'm not reading your sentence wrong, you're saying, from your experience, it's better to use a mutable registry and set it as default, than using def forms?
It doesn't have to be mutable (you also don't have to set it as default, you can use a schema schema), but yes, it's preferable to using def
> .. And I might refer it in other places, but I don't want the key to become ::city
>
You can do:
1. [:map ::city]
- qualified key + registry
2. [:map [:city ::city]]
- any key + registry
3. [:map [:city City]]
- any key + Var
At library code, you can't rely on the existence of the global registry, so 3 (or Schemas with explicit immutable registry) should be used. Used them all, leaning bit towards the global registry.
@UK0810AQ2 why do you find it preferable?