Fork me on GitHub
#malli
<
2023-10-12
>
escherize16:10:21

I could use some help with something where mu/update-in seems to be misbehaving. Am I holding it wrong or is it broken? 🧵

escherize16:10:32

Ultimately I’m trying to add a branch to an :orn schema, and not seeing what I expected: Given

(def my-schema
  [:schema {:registry {"test" [:orn [:string-node :string]]}} "test"])
(mu/update-in my-schema [0 0] mu/assoc :int-node :int)
;; => [:schema {:registry {"test" [:orn [:string-node :string]]}} "test"]
I expected to see an [:int-node :int] path under the :orn. Not sure why the above doesn’t work when below seems to do the right thing
(mu/get-in my-schema [0 0])
;; => [:orn [:string-node :string]]
(mu/assoc [:orn [:string-node :string]] :int-node :int)
;; => [:orn [:string-node :string] [:int-node :int]]

steveb8n01:10:18

I’ve been doing a lot of this lately. maybe I can help

🙏 1
steveb8n01:10:13

any kind of transform using registries is tricky. it’s much easier to deref the entire schema before starting any transforms

steveb8n01:10:25

once you have it fully local, then transforms are much easier to grok. does this help?

escherize02:10:44

I ended up using m/form and a postwalk. I have control over the shape of the schema coming in, so it’s really just a superstition sort of thing.

escherize02:10:33

it is for a convenience function for adding branches to my hiccup->html compiler https://github.com/escherize/huff#extendable-grammar 🙂

ikitommi19:10:13

So, all good with this one?

👍 1
DrLjótsson18:10:15

What is the difference between the :tuple and :cat schemas?

ikitommi19:10:54

:tuple is a fast fixed size vector. :cat is sequential schema with regex semantics. More powerful, bit slower.

ikitommi19:10:07

the perf difference between the two:

(require '[criterium.core :as cc])

(let [valid? (m/validator [:* int?])]
  (cc/quick-bench (valid? (range 10)))) ; Execution time mean : 2.7µs

(let [valid? (m/validator [:sequential int?])]
  (cc/quick-bench (valid? (range 10)))) ; Execution time mean : 0.12µs