eclipse / eclipse-collections

Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional and fluent API.
https://eclipse.dev/collections/
2.44k stars 613 forks source link

Allow for getting a generic view of primitive collections #746

Open victornoel opened 5 years ago

victornoel commented 5 years ago

I noticed the following need when manipulating primitive maps, but this apply to any primitive collection I believe, mutable and immutable alike.

Basically, I have a MutableObjectDoubleMap<T> and sometimes I need somewhere a MutableMap<T, Double>.

Currently what I would do is: map.keyValuesView().toMap(ObjectDoublePair::getOne, ObjectDoublePair::getTwo))

The problem with this is that it involves useless copying.

I would have liked to be able to write: map.asMap() and get a MutableMap view on my primitive map that boxes and unbox the values as needed depending on the operations used.

donraab commented 5 years ago

It would be nice to have asMap, asList, asSet, etc. for primitive collections.

This was functionality that was in the process of being added for primitive Lists and Sets. I don't think the work was ever completed. While it is straight forward, it is a lot of work. Support needs to be provided for Iterators, etc. Decisions need to be made on whether to support both read and write apis.