fastutil icon indicating copy to clipboard operation
fastutil copied to clipboard

Primitive type equivalent of Map#forEach is missing

Open markusheiden opened this issue 3 years ago • 5 comments

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.

markusheiden avatar Oct 15 '22 09:10 markusheiden

Map#fastForEach

vigna avatar Oct 15 '22 14:10 vigna

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

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.

markusheiden avatar Oct 15 '22 15:10 markusheiden

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

vigna avatar Oct 16 '22 07:10 vigna

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)

incaseoftrouble avatar Oct 16 '22 10:10 incaseoftrouble

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

Marcono1234 avatar Oct 26 '22 00:10 Marcono1234