All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jnape.palatable.lambda.functions.builtin.fn2.All Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
package com.jnape.palatable.lambda.functions.builtin.fn2;

import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.specialized.BiPredicate;

/**
 * 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 BiPredicate, Iterable> {

    private static final All INSTANCE = new All<>();

    private All() {
    }

    @Override
    public Boolean checkedApply(Fn1 predicate, Iterable as) {
        for (A a : as)
            if (!predicate.apply(a))
                return false;

        return true;
    }

    @SuppressWarnings("unchecked")
    public static  All all() {
        return (All) INSTANCE;
    }

    public static  Fn1, ? extends Boolean> all(Fn1 predicate) {
        return All.all().apply(predicate);
    }

    public static  Boolean all(Fn1 predicate, Iterable as) {
        return All.all(predicate).apply(as);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy