metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 205 forks source link

Unexpected entry when chaining calls to malli.util/assoc-in #891

Open ALai57 opened 1 year ago

ALai57 commented 1 year ago

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]]]]]]