ddimtirov / nuggets

nuggets is (yet another) utility library for Java
https://ddimtirov.github.io/nuggets/javadoc/io/github/ddimitrov/nuggets/package-summary.html
Apache License 2.0
4 stars 1 forks source link

Partial application for JDK functional objects #21

Closed ddimtirov closed 7 years ago

ddimtirov commented 7 years ago

It turns out that such utility functions does not yield significant simplification over creating a wrapping lambdas.

 Function fun1 = Functions.applyLeft(1, bifun);      // normal import
 Function fun2 = applyRight(1, bifun);               // static import on demand
 Function fun3 = x -> bifun.apply(x, 1);             // doing it explicitly

Supplier sup1 = Functions.apply(42, fun1);
Supplier sup2 = apply(42, fun1);
Supplier sup3 = () -> fun1.apply(42);

There is an argument to be made for reducing the syntactic noise in complex compositions, but in that case, introducing a local variable would be more beneficial than replacing a lambda with function call.

The prefix notation of the partial application would take a bit used to in Java world.

Finally, we can provide these only for specific functional interfaces, further diminishing the usefulness.