medley icon indicating copy to clipboard operation
medley copied to clipboard

Retain metadata for polyadic assoc-some

Open tomdl89 opened this issue 1 year ago • 4 comments

Fixes issue raised in #91

tomdl89 avatar Aug 12 '24 14:08 tomdl89

On a related note, reduce-map could benefit from this too: https://github.com/tomdl89/medley/commit/8fd5920491cf15deb55d30baddab69bbf908ee64 I'm not convinced https://github.com/weavejester/medley/issues/13 reached the right conclusion btw. Comparing to map filter remove etc doesn't seem to make sense, as those functions produce a lazy-seq from a potentially different coll, whereas map-vals filter-vals remove-vals etc always take a map and return a map. Indeed, update-vals in latest clojure versions (which is doing the same thing as map-vals) does retain metadata.

tomdl89 avatar Aug 12 '24 15:08 tomdl89

Thanks for the commit, and apologies for the delay in reviewing it. Can you add a simple test just to prevent any regressions in future.

With regard to #13, I was originally basing my decision on mapv, which takes a vector and returns a vector, but discards the metadata. It's interesting that with update-vals they've decided to go the other way.

I'm willing to keep metadata for maps if that's the precedent set by clojure.core. I'm just concerned about keeping behavior consistent.

weavejester avatar Aug 21 '24 19:08 weavejester

I think the reasoning is that functions that modify an object retain metadata, and sequence functions don't. update-vals follows after assoc and update by retaining metadata, whereas mapv follows after map which does not. I would expect an assoc-like function to retain metadata.

NoahTheDuke avatar Aug 21 '24 20:08 NoahTheDuke

Then perhaps the rule is that functions with the collection as the first argument retain metadata, and otherwise it doesn't. Hence update-vals retaining metadata, and mapv not doing so.

weavejester avatar Aug 22 '24 12:08 weavejester

Looks like this PR is still waiting on a test. Would you be able to write one @tomdl89, or do you not have time? If needs be, I can write one.

weavejester avatar Sep 25 '24 22:09 weavejester

Sorry for the delay @weavejester. Tests added 👍

tomdl89 avatar Oct 07 '24 19:10 tomdl89

Thanks! Could you squash the tests commit into the original? Then I'll merge it into master.

weavejester avatar Oct 09 '24 17:10 weavejester

Squashed @weavejester ✅

tomdl89 avatar Oct 09 '24 21:10 tomdl89

Merged! Thanks for the PR!

weavejester avatar Oct 09 '24 21:10 weavejester