weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
865 stars 66 forks source link

map-vals loses meta-data of containing collection [0.7.1] #13

Closed hlship closed 7 years ago

hlship commented 8 years ago

I've found that if I have a collection, a map with meta data, and execute medley/map-vals upon it, the resulting map does not have the meta-data.

(require '[medley.core :as medley])
=> nil
(def x (with-meta {:my-meta 1} {:foo 1}))
=> #'user/x
(-> (medley/map-vals inc x) meta)
=> nil
(meta x)
=> {:foo 1}
weavejester commented 8 years ago

That's how clojure.core/mapv works:

user=> (def x (with-meta [1] {:foo 1}))
#'user/x
user=> (meta (mapv inc x))
nil
user=> (meta x)
{:foo 1}
hlship commented 8 years ago

I'd love a clarification on what clojure.core functions maintain metadata. I've asked on Slack but no response so far. May need to add a Clojure issue.

weavejester commented 8 years ago

Collection functions don't seem to maintain metadata. So map, filter, remove etc. This is why the equivalent functions in Medley act in the same way.

hlship commented 8 years ago

I've added a merging-meta macro to my toolchest project for this purpose.