Fork me on GitHub

Did a PR on making :schema and :ref schemas behave better: 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:

  [:schema [:map [:x int?]]]
  [:map [:y int?]])
; => [:map [:x int?] [:y int?]]
2. mu/subschemas with both :ref & :schemas:
  [:ref {:registry {"Address" [:map
                               [:street :string]
                               [:address [:ref "Address"]]
                               [:neighbor [:ref "Neighbor"]]]
                    "Country" [:map [:name [:= "finland"]]]
                    "Neighbor" [:ref "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.

👍 3

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

👍 6

@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)

👍 3