Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: _Key must be integer_ when assoc called with :kw on a vec #774

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

piotr-yuxuan
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant