This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-16
Channels
- # announcements (5)
- # asami (4)
- # babashka (72)
- # beginners (241)
- # calva (15)
- # cider (2)
- # circleci (5)
- # clara (41)
- # clj-kondo (38)
- # cljsrn (4)
- # clojars (33)
- # clojure (283)
- # clojure-europe (41)
- # clojure-nl (9)
- # clojure-uk (11)
- # clojuredesign-podcast (14)
- # clojurescript (76)
- # conjure (12)
- # cryogen (42)
- # data-science (1)
- # datalog (6)
- # datomic (7)
- # depstar (10)
- # events (2)
- # figwheel-main (1)
- # fulcro (22)
- # funcool (1)
- # london-clojurians (1)
- # malli (8)
- # meander (11)
- # off-topic (12)
- # pathom (19)
- # re-frame (8)
- # reveal (34)
- # shadow-cljs (34)
- # sql (7)
- # vim (8)
- # xtdb (6)
Did a PR on making :schema
and :ref
schemas behave better: https://github.com/metosin/malli/pull/282. It has a BREAKING CHANGE as m/deref
would be recursive and does not throw.
these work after the PR:
1. mu/merge
and mu/union
with references:
(mu/merge
[:schema [:map [:x int?]]]
[:map [:y int?]])
; => [:map [:x int?] [:y int?]]
2. mu/subschemas
with both :ref
& :schema
s:
(mu/subschemas
[:ref {:registry {"Address" [:map
[:street :string]
[:address [:ref "Address"]]
[:neighbor [:ref "Neighbor"]]]
"Country" [:map [:name [:= "finland"]]]
"Neighbor" [:ref "Address"]}}
"Address"])
;[{:path [], :in [], :schema [:ref {:registry {"Address" [:map
; [:street :string]
; [:address [:ref "Address"]]
; [:neighbor [:ref "Neighbor"]]]
; "Country" [:map [:name [:= "finland"]]]
; "Neighbor" [:ref "Address"]}}
; "Address"]}
; {:path [0 0], :in [], :schema [:map
; [:street :string]
; [:address [:ref "Address"]]
; [:neighbor [:ref "Neighbor"]]]}
; {:path [0 0 :street], :in [:street], :schema :string}
; {:path [0 0 :address], :in [:address], :schema [:ref "Address"]}
; {:path [0 0 :neighbor], :in [:neighbor], :schema [:ref "Neighbor"]}]
if you are in business of generating forms from schemas, mu/subschemas
is your best friend.
m/walk
can be configured with ::m/walk-refs
and ::m/walk-schema-refs
to walk over none, some of all references. Does not StackOverFlow, walks a given reference just once. cheers.
is there some kind of way to speed up m/validate
?
I have a real edge case, I automatically generated a schema for a structure that potentially can contain 1294 fields (a tree structure...) when I ran validate it took a few seconds on a empty map.
would it run quicker if I used a registry for things that are "common"?
I think malli supports something like lazy validation and/or lazy schemas - I've seen this being mentioned in a conversation with ikitommi and jeroenvandijk
@jarvinenemil not sure if it is still idiomatic Malli and it can be more optimized, but here is how you could do lazy loading (see lookup-type) https://github.com/jeroenvandijk/aws.cloudformation.malli/blob/master/src/adgoji/aws/cloudformation/malli/validation.clj