This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-12
Channels
- # adventofcode (1)
- # announcements (1)
- # atom-editor (4)
- # aws (4)
- # babashka (7)
- # beginners (46)
- # biff (14)
- # calva (11)
- # cljdoc (2)
- # clojure (78)
- # clojure-art (1)
- # clojure-austin (1)
- # clojure-europe (50)
- # clojure-nl (2)
- # clojure-norway (22)
- # clojure-spec (2)
- # clojure-uk (2)
- # clojurescript (72)
- # conjure (6)
- # core-typed (6)
- # eastwood (4)
- # events (1)
- # figwheel-main (11)
- # fulcro (1)
- # guix (1)
- # helix (13)
- # jobs (2)
- # jobs-discuss (4)
- # kaocha (2)
- # malli (5)
- # off-topic (7)
- # pathom (22)
- # pedestal (9)
- # re-frame (29)
- # reagent (7)
- # releases (2)
- # remote-jobs (1)
- # rewrite-clj (12)
- # shadow-cljs (44)
- # sql (13)
- # squint (2)
- # xtdb (17)
Can I generate a value from a registry? Something like:
(def reg
{::id int?
::name string?
::user [:tuple ::id ::name]})
(mg/generate {:registry reg} ::user)
Yes, by wrapping it in [:schema]
:
(mg/generate [:schema {:registry reg} ::user])
It works since generate
requires a schema to generate examples for. A registry is not a schema, just a map. So you need to create a schema that uses your registry.
As https://github.com/metosin/malli#local-registry, any schema can have a local registry property, e.g. [:map {:registry ,,,}]
. Since you don't have such a schema in your case, you can use the generic [:schema]
one, and just refer to a named one from the local registry.
An alternative would be the m/schema
function to instantiate the schema explicitly. Remember that forms such as [:map]
are not schemas yet, but will be instantiated on demand. You can explicitly turn them into schemas using m/schema
.
Hope that helps!
That is much more clear, thanks for the thoughtful answer @U031CHTGX1T