Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.function.*;
- public class ClosureProps {
- public static Predicate<Integer> union(Predicate<Integer> memA, Predicate<Integer> memB) {
- return (n) -> memA.test(n) || memB.test(n);
- }
- // tests
- public static boolean isSmall(Integer n) { return n < 10; }
- public static boolean divBy5(Integer n) { return n % 5 == 0; }
- public static void main(String args[]) {
- Predicate<Integer> mem = union(ClosureProps::isSmall, ClosureProps::divBy5);
- for(int i = 0; i < 21; i++) {
- System.out.println("mem(" + i + ") = " + mem.test(i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement