malli
malli copied to clipboard
Unexpected entry when chaining calls to malli.util/assoc-in
Copied from a Slack thread https://clojurians.slack.com/archives/CLDK6MFMK/p1680790963043859
I came across a Malli behavior I didn’t understand and wanted some advice.
When I chain two mu/assoc-in calls, it seems like the resultant schema has a duplicated field (see below, new-field shows up twice). Is this expected behavior? Am I misusing the assoc-in function?
(def Address
[:map
[:street string?]
[:city string?]
[:zip int?]
[:lonlat [:tuple double? double?]]])
(def Address2
(-> Address
(mu/assoc-in [:new-field :v1] [:map [:foo :int]])
(mu/assoc-in [:new-field :v2] [:map [:foo :int]])))
Address2
;; => [:map [:street string?]
;; [:city string?]
;; [:zip int?]
;; [:lonlat [:tuple double? double?]]
;; [:new-field [:map [:v1 [:map [:foo :int]]]]]
;; [:new-field [:map [:v1 [:map [:foo :int]]]
;; [:v2 [:map [:foo :int]]]]]]