malli

David G 2024-09-17T22:38:15.300559Z

Does malli.util respect registries? I've setup mine according to the doc on github but stuff like malli.util/get-in don't work unless I deref the atom. malli.core does respect the registry

opqdonut 2024-09-18T05:09:06.866969Z

I'm not quite following you, could you give some code examples? Which atom are you talking about?

David G 2024-09-18T17:40:22.490709Z

Sure thing. I used the code in https://github.com/metosin/malli/blob/master/docs/reusable-schemas.md#schemas-via-global-registry

(require '[malli.registry :as mr])

(defonce *registry (atom {}))

(defn register! [type ?schema]
  (swap! *registry assoc type ?schema))

(mr/set-default-registry!
 (mr/composite-registry
  (m/default-schemas)
  (mr/mutable-registry *registry)))
In my REPL:
repl> (require '[malli.core :as m])
nil
repl> (require '[malli.registry :as mr])

(defonce *registry (atom {}))

(defn register! [type ?schema]
  (swap! *registry assoc type ?schema))

(mr/set-default-registry!
 (mr/composite-registry
  (m/default-schemas)
  (mr/mutable-registry *registry)))
nilnil#'repl/register!#object[malli.registry$composite_registry$reify__15462 0x33b05f17 "malli.registry$composite_registry$reify__15462@33b05f17"]
repl> (register! ::foo [:map [:a :int]])
#:repl{:foo [:map [:a :int]]}
repl> (require '[malli.util :as mu])
nil
repl> (mu/get ::foo :a)
nil
repl> (mu/get [:map [:a :int]] :a)
:int
repl> (m/deref ::foo)
[:map [:a :int]]
repl> 

David G 2024-09-18T17:41:54.368469Z

Am I suppose to pass in the registry in the options? The atom I mentioned was the registry itself

2024-09-18T18:39:23.368839Z

It's probably a good idea to deref before using mu/get. there are lots of wrappers of :map like :merge and :union , I'm guessing ::foo is another similar example.

💯 1
2024-09-18T18:39:50.362239Z

Perhaps ::foo implements LensSchema, worth trying (mu/get-in ::foo [0 :a])

🔥 1
David G 2024-09-18T19:05:28.711879Z

(mu/get-in ::foo [0 :a]) works! Although in this case it does seem better to just deref/deref-recursively

👍 1