amaembo / streamex

Enhancing Java Stream API
Apache License 2.0
2.18k stars 249 forks source link

Add toMapKey() method #238

Closed stickfigure closed 2 years ago

stickfigure commented 3 years ago

A minor feature request:

IMO, the streams designers made one ergonomic mistake - the one-argument toMap() method takes a valuemapper instead of a keymapper. I guess they flipped a coin? In my entire life I have never used the one-argument valuemapper, but I write this all the time:

toMap(Thing::getKey, Function.identity())

It would be more ergonomic to simply write:

toMapKey(Thing::getKey)

(or any other method name; it doesn't have to be toMapKey)

It would be lovely if StreamEx added this little convenience method. Thanks!

amaembo commented 2 years ago

Thanks. I renamed methods to valuesToMap(), valuesToSortedMap() and valuesToNavigableMap().

stickfigure commented 2 years ago

That's great, thanks!