trying to wrap my head around some of malli concepts:
1. what are the differences of using :or and :alt ? i can express
(m/explain
[:* [:cat string? [:alt string? boolean?]]]
["-server" "foo" "-verbose" 11 "-user" "joe"])
as
(m/explain
[:* [:cat string? [:or string? boolean?]]]
["-server" "foo" "-verbose" 11 "-user" "joe"])
2. what are the differences (pros and cons) of attaching schemas to the registry as opposed to a var (using def) and reference it?
(def address
[:map
[:street :string]])
(m/validate
[:map
[:id :int]
[:address #'address]]
{:id 2
:address {:street "street"}})
(m/validate
[:map {:registry {::address [:map
[:street :string]]}}
[:id :int]
::address]
{:id 2
::address {:street "street"}})IIRC sequence schemas get flattened while :or breaks that. Try nesting a cat under the alt and see what happens
thanks ill check it
do you know if there's a recursive mu/optional-keys?
Like a lens? No
I've written that util like 3 times now 😛
so why can't I find a copy of it anywhere...
here's one:
(defn make-all-keys-optional
"Recursively apply mu/optional-keys to map schemas"
[schema]
(m/walk
schema
(m/schema-walker
(fn [schema]
(if (= :map (m/type schema))
(mu/optional-keys schema)
schema)))))and yeah, re: :or vs :alt, :alt is meant for seqex schemas, it corresponds to | in regex. :or is meant for general use