malli icon indicating copy to clipboard operation
malli copied to clipboard

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

Open ALai57 opened this issue 2 years ago • 0 comments

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

ALai57 avatar Apr 11 '23 16:04 ALai57