com.jnape.palatable.lambda.functions.builtin.fn2.All Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda Show documentation
Show all versions of lambda Show documentation
Functional patterns for Java
package com.jnape.palatable.lambda.functions.builtin.fn2;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;
import java.util.function.Function;
/**
* Eagerly apply a predicate to each element in an Iterable
, returning true
if every element
* satisfies the predicate, and false
otherwise. This method short-circuits on the first false
* evaluation.
*
* @param The input Iterable element type
* @see Any
*/
public final class All implements Fn2, Iterable, Boolean> {
private All() {
}
@Override
public Boolean apply(Function super A, Boolean> predicate, Iterable as) {
for (A a : as)
if (!predicate.apply(a))
return false;
return true;
}
public static All all() {
return new All<>();
}
public static Fn1, Boolean> all(Function super A, Boolean> predicate) {
return All.all().apply(predicate);
}
public static Boolean all(Function super A, Boolean> predicate, Iterable as) {
return All.all(predicate).apply(as);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy