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

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

Closed
hlship opened this issue Feb 17, 2016 · 4 comments
Closed

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

hlship opened this issue Feb 17, 2016 · 4 comments

Comments

@hlship
Copy link

hlship commented Feb 17, 2016

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
Copy link
Owner

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
Copy link
Author

hlship commented Feb 17, 2016

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
Copy link
Owner

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
Copy link
Author

hlship commented Feb 17, 2016

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

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

No branches or pull requests

2 participants