Skip to content

Instantly share code, notes, and snippets.

@mknudsen
Created January 10, 2015 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mknudsen/006930f5b3caab05813c to your computer and use it in GitHub Desktop.
Save mknudsen/006930f5b3caab05813c to your computer and use it in GitHub Desktop.
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