This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-11
Channels
- # announcements (3)
- # babashka (62)
- # beginners (58)
- # calva (40)
- # cider (3)
- # clj-kondo (75)
- # cljdoc (14)
- # clojars (8)
- # clojure (110)
- # clojure-australia (6)
- # clojure-europe (38)
- # clojure-hungary (1)
- # clojure-india (4)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-spec (4)
- # clojure-uk (3)
- # clojurescript (45)
- # conjure (4)
- # cursive (35)
- # data-science (1)
- # datomic (11)
- # events (2)
- # exercism (4)
- # figwheel-main (4)
- # fulcro (103)
- # graphql (16)
- # helix (1)
- # holy-lambda (16)
- # honeysql (1)
- # introduce-yourself (3)
- # jobs (1)
- # keyboards (2)
- # lsp (4)
- # malli (11)
- # membrane-term (3)
- # mount (2)
- # nextjournal (2)
- # off-topic (53)
- # pathom (30)
- # pedestal (2)
- # portal (22)
- # rdf (1)
- # re-frame (7)
- # reagent (3)
- # reitit (5)
- # remote-jobs (6)
- # shadow-cljs (20)
- # sql (8)
- # tools-build (10)
- # vim (4)
- # xtdb (12)
Is there a way to create a custom Malli tag that will allow me to write:
[:record
[:user-id :string]
[:num-of-purchases :int]]
And it would be the same as:
[:and
[:map-of :keyword :any]
[:map
[:user-id :string]
[:num-of-purchases :int]]
I need this because for the moment JSON decoder doesn't convert :map
key strings to keywords https://github.com/metosin/malli/issues/568@U0L91U7A8 you could use the json-transformer version I posted on the issue. (You might want to combine with :map-of
code from the Malli.transform version)
But yeah if you create your own registry, you could define :record
as :map-of
+ :map
How it would look like?
Does generate cache the generator?
mg/generator
is what you're looking for I think
Yes but if i skip the mg/generator, generate will create a generator, is that generator cached?
not yet, but in few mins it does - https://github.com/metosin/malli/pull/575/files
mg/generator
is still bit faster, as there is no cache lookup. Caching is done on Schema instance level, so calling generate with just hiccup effectively bypasses the cache.
merged, so generators are also cached by default (with the Schema instance):
(def schema
(m/schema
[:map
[:x boolean?]
[:y {:optional true} int?]
[:z [:map
[:x boolean?]
[:y {:optional true} int?]]]]))
(comment
;; 119µs
;; 16µs (cache generator)
(p/bench (mg/generate schema)))
merged, so generators are also cached by default (with the Schema instance):
(def schema
(m/schema
[:map
[:x boolean?]
[:y {:optional true} int?]
[:z [:map
[:x boolean?]
[:y {:optional true} int?]]]]))
(comment
;; 119µs
;; 16µs (cache generator)
(p/bench (mg/generate schema)))