package com.tvd12.ezyfox.function;

import java.util.Arrays;
import java.util.function.Predicate;

@SuppressWarnings({"rawtypes", "unchecked"})
public final class EzyPredicates {

	public static final Predicate ALWAY_TRUE = o -> true;
	
	private EzyPredicates() {
	}
	
	public static <T> Predicate<T> alwayTrue() {
		return ALWAY_TRUE;
	}
	
	public static Predicate and(Iterable predicates) {
		return t -> {
			for(Object predicate : predicates)
				if(!((Predicate)predicate).test(t))
					return false;
			return true;
		};
	}
	
	public static Predicate or(Predicate... predicates) {
		Predicate predicate = or(Arrays.asList(predicates));
		return predicate;
	}
	
	public static Predicate or(Iterable<Predicate> predicates) {
		return t -> {
			for(Predicate predicate : predicates)
				if(predicate.test(t))
					return true;
			return false;
		};
	}
	
}

@@ -700,19 +700,8 @@
 able
-%3CPredicate%3E
  pre
@@ -734,25 +734,22 @@
 %0A%09%09%09for(
-Predicate
+Object
  predica
@@ -772,16 +772,28 @@
 %0A%09%09%09%09if(
+((Predicate)
 predicat
@@ -793,16 +793,17 @@
 redicate
+)
 .test(t)

update EzyPredicates