malli
malli copied to clipboard
fix: _Key must be integer_ when `assoc` called with :kw on a vec
At some point I stumbled upon this unexpected behaviour:
(def explanation
{:value {:my-field ["id" "credated-at"]} ; Come from an http request, decoded with malli.
:errors (list {:path [:my-field 0]
:in [:my-field :credated-at]
:schema [:enum :created-at :id]
:value :credated-at})})
(me/humanize explanation)
; => (IllegalArgumentException. "Key must be integer")
(alter-var-root
(var me/-push)
(constantly (fn [x k v fill]
(let [i (when (int? k) k)
x' (cond-> x (and i (sequential? x) (> k (count x))) (me/-fill k fill))]
(cond (nil? x') (assoc x' k v)
(and (associative? x') i) (assoc x' i v)
(associative? x') (assoc x' (count x') v)
(set? x') (conj x' v)
:else (apply list (assoc (vec x') k v)))))))
(me/humanize explanation)
; => {0 [["should be either :created-at or :id"]]}