Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import java.util.function.*;
  2. public class ClosureProps {
  3.  
  4. public static Predicate<Integer> union(Predicate<Integer> memA, Predicate<Integer> memB) {
  5. return (n) -> memA.test(n) || memB.test(n);
  6. }
  7.  
  8.  
  9. // tests
  10.  
  11. public static boolean isSmall(Integer n) { return n < 10; }
  12. public static boolean divBy5(Integer n) { return n % 5 == 0; }
  13.  
  14.  
  15. public static void main(String args[]) {
  16. Predicate<Integer> mem = union(ClosureProps::isSmall, ClosureProps::divBy5);
  17. for(int i = 0; i < 21; i++) {
  18. System.out.println("mem(" + i + ") = " + mem.test(i));
  19. }
  20. }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement