Activity

I don't think that always makes sense. Say you had a map of string to integers with a custom comparator created by sorted-map-by. If you use empty, you'd still have a map with a custom comparator which you would pour integer keys into and would likely throw a ClassCastException.

Alex Miller
added a comment - 26/Jul/14 8:43 AM I don't think that always makes sense. Say you had a map of string to integers with a custom comparator created by sorted-map-by. If you use empty, you'd still have a map with a custom comparator which you would pour integer keys into and would likely throw a ClassCastException.
What is the use case that led you to this ticket?

My use case is that I have a custom type that implements IPersistentMap. If I use map-invert over it, I get a regular map back, which is problematic because regular maps don't allow multiple values for the same key, unlike my multimap implementation, so I loose information.

Gregory Schlomoff
added a comment - 26/Jul/14 9:14 AM Hello Alex, thanks for commenting.
My use case is that I have a custom type that implements IPersistentMap. If I use map-invert over it, I get a regular map back, which is problematic because regular maps don't allow multiple values for the same key, unlike my multimap implementation, so I loose information.
(map-invert (my-multimap :a 1, :b 1))
=> {1 :b} ; lost the (1 :a) entry because regular maps don't allow duplicate keys
Maybe a solution would be to make a version of map-invert that takes a map to insert the inverted entries into?
I'm not adamant over this, if you think there is no elegant solution for this issue we can close it.

Alex Miller
added a comment - 27/Jul/14 7:28 AM I don't think this enhancement makes sense as written - there are cases where it would be a breaking change for existing code.
I do think your specified problem makes sense though. One enhancement might be to have a variant of map-invert (different arity or map-invert-into that took an additional map target param).