weavejester / medley

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

Add function hash-map-by #28

Closed hlship closed 5 years ago

hlship commented 6 years ago

I end up copy-and-pasting this function into a lot of my projects, so this feels like a good home for it.

martinklepsch commented 5 years ago

Would love to see this added as well. 👍

borkdude commented 5 years ago

Me too. A better name for it is maybe index-by which I've seen in a couple of other places.

fhalde commented 5 years ago

Can index-by be made more generic to accept a collision handling function? This will provide more flexibility in the strategies to be used for handling same keys!

weavejester commented 5 years ago

I don't think index-by should be made mode complex. Currently there's a nice similarity between group-by, which adds values to a vector, and index-by, which overwrites values.

If we want a function that handles collisions, I think it should be separate, because its functionality would be a superset of the functionality in index-by and group-by. I'm also not sure how useful such a function would be.