;; merge
(merge {:a :b} [:a :c]) ;=> {:a :c}
;; merge-with
(merge-with (fn [_ x] x) {} {:a :b} [:a :c])
;; => class clojure.lang.Keyword cannot be cast to class java.util.Map$Entry
I think this happens because merge-with
eventually calls seq
on the "Map", expecting to get a "Map Entry" from which then it can extracts key
and value
, and fails when receiving a Vector, because seq
will just yield one element at a time:
(key (first (seq {:a :c}))) ;; => :a
(key (first (seq [:a :c])))
;; => class clojure.lang.Keyword cannot be cast to class java.util.Map$Entry
I think it is justified to expect that (partial merge-with (fn [_ x] x))
should behave exactly as merge
and my proposal is to make it happen, if what I described makes sense.
Thank you!