java-design-patterns
java-design-patterns copied to clipboard
Currying
I's a functional programming design pattern. As far as I understand you call a function with less parameters than usual and it can be used to defer processing when it has many steps involved.
UML example
@startuml
'https://plantuml.com/class-diagram
interface BiFunction <ParamType1, ParamType2, ResultType>{
}
interface Curried<ParamType1, ParamType2 extends Simple> {
+ParamType2 apply(final ParamType1 a);
}
interface Simple<ParamType1, ParamType2, ResultType> extends BiFunction {
+ResultType apply(final ParamType1 a, final ParamType2 b);
}
@enduml
With the curried version you can do stuff like:
System.out.println(curriedAdd.apply(4).apply(5));
Function1<Integer, Integer> adder5 = curriedAdd.apply(5);
//some complicate and time consuming process here
System.out.println(adder5.apply(4));
System.out.println(adder5.apply(6));
There is a concrete example about currying in Java on Baeldung's website: https://www.baeldung.com/java-currying
hi @iluwatar , can I work on this issue for Hacktoberfest?
Sure @januslinhc, it's now assigned to you
Hey @iluwatar, could I work on this issue?
All right @hkattt, you're free to proceed
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@hkattt is still working on this