This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-12
Channels
- # aleph (61)
- # announcements (2)
- # babashka (65)
- # beginners (64)
- # calva (2)
- # clerk (1)
- # cljsrn (1)
- # clojure (60)
- # clojure-austin (7)
- # clojure-europe (13)
- # clojure-italy (2)
- # clojure-losangeles (4)
- # clojure-nl (2)
- # clojure-norway (94)
- # clojure-romania (2)
- # clojure-uk (7)
- # clojuredesign-podcast (5)
- # clojurescript (3)
- # core-typed (2)
- # datomic (42)
- # docker (24)
- # emacs (10)
- # exercism (50)
- # graphql (83)
- # honeysql (25)
- # hyperfiddle (12)
- # malli (13)
- # membrane (49)
- # off-topic (50)
- # podcasts-discuss (1)
- # re-frame (3)
- # reagent (12)
- # reitit (5)
- # releases (2)
- # remote-jobs (8)
I could use some help with something where mu/update-in seems to be misbehaving. Am I holding it wrong or is it broken? 🧵
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]]
any kind of transform using registries is tricky. it’s much easier to deref the entire schema before starting any transforms
once you have it fully local, then transforms are much easier to grok. does this help?
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.
it is for a convenience function for adding branches to my hiccup->html compiler https://github.com/escherize/huff#extendable-grammar 🙂
What is the difference between the :tuple
and :cat
schemas?
:tuple
is a fast fixed size vector. :cat
is sequential schema with regex semantics. More powerful, bit slower.
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
Thanks!