Created
January 10, 2015 18:07
-
-
Save mknudsen/006930f5b3caab05813c to your computer and use it in GitHub Desktop.
currying in java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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