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/568Why not add your own transformer?
@viebel 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)))