This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-23
Channels
- # announcements (2)
- # babashka (25)
- # beginners (33)
- # biff (13)
- # calva (13)
- # clerk (82)
- # clj-commons (3)
- # clj-kondo (8)
- # clj-on-windows (23)
- # cljdoc (6)
- # clojure (16)
- # clojure-belgium (1)
- # clojure-dev (58)
- # clojure-europe (53)
- # clojure-nl (1)
- # clojure-norway (15)
- # clojure-uk (2)
- # clojurescript (17)
- # core-async (5)
- # cursive (6)
- # datahike (1)
- # datomic (8)
- # emacs (25)
- # etaoin (21)
- # events (4)
- # graalvm (33)
- # honeysql (7)
- # hyperfiddle (1)
- # lsp (49)
- # luminus (4)
- # malli (18)
- # off-topic (63)
- # reagent (11)
- # releases (1)
- # shadow-cljs (200)
- # timbre (1)
- # tools-build (17)
After working a bit with creating custom schemas, I think that would be useful if :gen/gen value can be a delay or function, for initialize the generator lazily, only when it is used. What do you think?
with lazy I mean having the ability to defer the creting the generator instance when it is requested
Something like this that I have in mind, provide a function that returns the generator, when it is requested, also there is the option to use clojure.core/delay, it caches the value on second use
but having the ability to pass a symbol and resolve it once is needed it also a nice to have
what do you think about the "delay" or function ? if it is ok, I can try to make draft PR for it
this also works btw:
(defrecord My [])
(mr/set-default-registry!
(merge
(m/default-schemas)
{::my (m/-simple-schema
{:pred any?
:type ::my
:type-properties {:gen/schema ::my-map
:gen/fmap map->My}})
::my-map [:map [:x :int] [:y :int]]}))
(mg/sample ::my)
;(#{:x 0, :y 0}
; #{:x -1, :y 0}
; #{:x 0, :y 0}
; #{:x 0, :y 0}
; #{:x 0, :y 1}
; #{:x 7, :y 0}
; #{:x -6, :y -1}
; #{:x 2, :y -7}
; #{:x -2, :y -4}
; #{:x 36, :y -1})
What's the correct way to use mu/update-properties
on a schema in a registry? When I try just merging the return value back into the registry under the same key, I get invalid-schema
exceptions.
for example:
(-> registry
(update ::fqh/commit mu/update-properties assoc :encode/edn
(partial encode-commit-edn parsed-context))
(update ::expanded-iri mu/update-properties assoc :encode/edn
#(json-ld/expand-iri % parsed-context))))
if you are constructing the registry and try to reference schemas that are not yet registered, it’s an error.
I would use https://github.com/metosin/malli#mutable-registry and add the schemas imperative one-by-one. Just like with spec.
The schemas are already in the registry. I'm just trying to update their properties. But the returned value from mu/update-properties
is invalid.
but perhaps a mutable registry is still the right answer there