Advertisement
Guest User

chickenMadras

a guest
Feb 10th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1.  
  2. import java.util.function.BiFunction;
  3. import java.util.function.Function;
  4.  
  5. public class Balti {
  6.  
  7. /**
  8. * Creates a function which to curry the supplied function
  9. * @param function the function to curry
  10. * @return the curry gen function for the bifunction
  11. */
  12. private static <A, B, C> Function<A, Function<B, C>> curry(BiFunction<A, B, C> function) {
  13. return (a) -> (b) -> function.apply(a, b);
  14. }
  15.  
  16. public static void main(String[] args) {
  17. BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
  18.  
  19. Function<Integer, Function<Integer, Integer>> curry = curry(add);
  20.  
  21. Function<Integer, Integer> addToFive = curry.apply(5);
  22.  
  23. // will output ten
  24. System.out.println(addToFive.apply(5));
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement