Given the following function:
public static <X> List<X> filterWithVarargPredicates(
List<X> allProducts,
Predicate<X>... predicates
) {
for (Predicate<X> predicate : predicates) {
allProducts = allProducts.stream()
.filter(predicate)
.collect(toList());
}
return allProducts;
}
Is there any way to consume all the predicates without having to loop through them and re-assign to the list? For instance, it'd be great if .stream()
had a filter that took varargs, or some way to do that within a single stream.