vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.74k stars 194 forks source link

Primitive type equivalent of Map#forEach is missing #279

Open markusheiden opened 1 year ago

markusheiden commented 1 year ago

I would like to iterate a map's entry set without the need for boxing. I found no equivalent for Map#forEach though.

One could achieve this via iterating over *2*EntrySet() but the code looks less readable then.

vigna commented 1 year ago

Map#fastForEach

markusheiden commented 1 year ago

Sorry for bugging you again, but there is just a FastEntrySet#fastForEach(Consumer).

I opened this issue because I am missing the "syntactic sugar variant" using a BiConsumer. That allows for way better readable code like map.forEach((key, value) -> ...) instead of using the "clumsy" Entry#getKey and Entry#get*Value with the method mentioned above.

So it would be nice if you would reopen this issue.

vigna commented 1 year ago

I now see your point. The problem is that we do not have type-specific BiConsumers. Are there some provided by the JDK?

incaseoftrouble commented 1 year ago

if I recall correctly, there are none indeed! It would certainly be nice to have it, not only from code style but also performance (EntrySet#forEach allocates objects)

Marcono1234 commented 1 year ago

It looks like this also came up when Java 8 support was discussed: https://github.com/vigna/fastutil/issues/64#issuecomment-303649328