Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
currying in java 8
import java.util.function.BiFunction;
import java.util.function.Function;
public class Currying {
// A,B -> C
// A -> B -> C
public static BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
public static <A, B, C> Function<A, Function<B, C>> curry(BiFunction<A, B, C> fnToCurry) {
return a -> b -> fnToCurry.apply(a, b);
}
public static void main(String[] args) {
System.out.println("add:" + add.apply(2, 3));
System.out.println("add:" + curry(add).apply(2).apply(3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment