Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.function.BiFunction;
- import java.util.function.Function;
- public class Balti {
- /**
- * Creates a function which to curry the supplied function
- * @param function the function to curry
- * @return the curry gen function for the bifunction
- */
- private static <A, B, C> Function<A, Function<B, C>> curry(BiFunction<A, B, C> function) {
- return (a) -> (b) -> function.apply(a, b);
- }
- public static void main(String[] args) {
- BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
- Function<Integer, Function<Integer, Integer>> curry = curry(add);
- Function<Integer, Integer> addToFive = curry.apply(5);
- // will output ten
- System.out.println(addToFive.apply(5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement