Function reference: ignoring the returned value


#1

Hi!

I have this:

Sponge.getCommandManager().getOwnedBy(this).forEach { Sponge.getCommandManager().removeMapping(it) }

and would like to write it as a function reference:

Sponge.getCommandManager().getOwnedBy(this).forEach(Sponge.getCommandManager()::removeMapping)

But this is not possible because CommandManager#removeMapping returns an optional of the removed mapping(if the given one was registered before). But forEach does only accept Unit returning functions.

Should I use map instead, or is this bad practice?