applitopia / immutable-sorted

This is an extension of Immutable.js that provides sorted collections SortedMap and SortedSet. The current implementation is using highly optimized B-tree memory structure.
http://applitopia.github.io/immutable-sorted/
Other
29 stars 6 forks source link

SortedMap operating by value #12

Closed RKleminski closed 4 years ago

RKleminski commented 5 years ago

It might be that I don't understand something basic about the under-the-hood workings of a SortedMap, but why is there no way to have it operate on the basis of values? The comparator operates on keys.

For context, in my use case, I want to store objects in a SortedMap that have multiple fields and are identified by an ID. I previously used OrderedMap, but I find myself in need to ensure sorting by a date field. The way the comparator works, I am required to include the date in the keys for every object.

Is a SortedMap that sorts by value planned as a possible extension, or is there a strong reason to keep this operation only available via .sort functions available to Maps in general?

applitopia commented 5 years ago

Hi, perhaps the SortedSet with a custom comparator is a better fit for your use case. You just work with values and you don't worry about the keys. You will not be able to lookup by ID though.

Anther options is to keep a traditional Map for looking up by ID, and a companion SortedMap with key=Date and value=ID that will be sorted by date.