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

com.jnape.palatable.lambda.functions.builtin.fn2.Any 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.Fn2;
import com.jnape.palatable.lambda.functions.specialized.BiPredicate;

import java.util.function.Function;

/**
 * Eagerly apply a predicate to each element in an Iterable, returning true if any element
 * satisfies the predicate, and false otherwise. This method short-circuits on the first true
 * evaluation.
 *
 * @param  The input Iterable element type
 * @see All
 */
public final class Any implements BiPredicate, Iterable> {

    private Any() {
    }

    @Override
    public Boolean apply(Function predicate, Iterable as) {
        for (A a : as)
            if (predicate.apply(a))
                return true;

        return false;
    }

    public static  Any any() {
        return new Any<>();
    }

    public static  Fn1, Boolean> any(Function predicate) {
        return Any.any().apply(predicate);
    }

    public static  Boolean any(Function predicate, Iterable as) {
        return Any.any(predicate).apply(as);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy