Logo

Programming-Idioms

History of Idiom 37 > diff from v13 to v14

Edit summary for version 14 by :
New Java implementation by user [javasucks]

Version 13

2015-11-30, 12:37:28

Version 14

2016-02-17, 10:15:42

Idiom #37 Currying

Technique of transforming a function that takes multiple arguments and returning a function for which some of the arguments are preset.

Idiom #37 Currying

Technique of transforming a function that takes multiple arguments and returning a function for which some of the arguments are preset.

Imports
import java.util.function.*;
Code
IntBinaryOperator simpleAdd = (a, b) -> a + b;
IntFunction<IntUnaryOperator> curriedAdd = a -> b -> a + b;
System.out.println(simpleAdd.applyAsInt(4, 5));
System.out.println(curriedAdd.apply(4).applyAsInt(5));
Origin
http://stackoverflow.com/questions/6134278/does-java-support-currying/14750362#14750362