sneaky-java icon indicating copy to clipboard operation
sneaky-java copied to clipboard

API design improvement proposal: overload all methods

Open mleg opened this issue 3 years ago • 2 comments

Found annoying to figure out each time which method to use. I'm not very good at rememebering all Java functional interfaces.

Proposal:

Give all Sneaky class methods same name (unchecked for example) thus overloading them. Instead of writing

myStream.forEach(Sneaky.consumer(lambda));

it would look like

myStream.forEach(unchecked(lambda));

Notice static import now is more sensible.
Also it helps with refactoring when lambda signature changes.

mleg avatar Mar 24 '22 15:03 mleg

@mleg Sounds like a good idea! Pull requests are welcome

SimonHarmonicMinor avatar Mar 24 '22 15:03 SimonHarmonicMinor

@mleg By the way, I don't think that you should rename all methods in Sneaky class. But instead there has to be a separate unchecked method with required overloaded parameters. Because sometimes we do need to create particular functional wrapper.

var supplier = Sneaky.supplier(() -> 1);

SimonHarmonicMinor avatar Mar 24 '22 15:03 SimonHarmonicMinor