EC by Example: FlatCollect into primitive collections
I have recently contributed to Eclipse Collections project implementing flatCollectByte
, flatCollectChar
, flatCollectInt
, flatCollectShort
, flatCollectDouble
, flatCollectFloat
, flatCollectLong
and flatCollectBoolean
methods.
EC already had collectByte
, collectChar
and other primitive collect
implementations. Adding primitive flatCollect
implementations improved the symmetry between collect
and flatCollect
APIs in addition to adding useful functionality.
What is FlatCollect?
FlatCollect introduction by Donald Raab
FlatCollectInt examples
Here is an example of using flatCollectInt
to collect unique ages of all pets that belong to a list of people into IntSet.
Here’s another example of using FlatCollectInt
to get counts by pet age by collecting into IntHashBag:
This is how getPetAges
is implemented:
The new flatCollect
methods will be available in the next release of EC (10.3).
For more information about Eclipse Collections, check out this presentation.