Package io.vavr

Interface CheckedPredicate<T>

  • Type Parameters:
    T - the type of the input to the predicate
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface CheckedPredicate<T>
    A Predicate that is allowed to throw checked exceptions.
    • Method Detail

      • of

        static <T> CheckedPredicate<T> of​(@NonNull CheckedPredicate<T> methodReference)
        Creates a CheckedPredicate from the given method reference or lambda.

        Example usage:

        
         final CheckedPredicate<Boolean> checkedPredicate = CheckedPredicate.of(Boolean::booleanValue);
         final Predicate<Boolean> predicate = checkedPredicate.unchecked();
        
         // returns true
         predicate.test(Boolean.TRUE);
        
         // may throw an exception
         predicate.test(null);
         
        Type Parameters:
        T - the type of values tested by the predicate
        Parameters:
        methodReference - typically a method reference, e.g. Type::method
        Returns:
        a new CheckedPredicate wrapping the given method reference
        See Also:
        CheckedFunction1.of(CheckedFunction1)
      • test

        boolean test​(T t)
              throws java.lang.Throwable
        Evaluates this predicate on the given argument.
        Parameters:
        t - the input argument
        Returns:
        true if the argument satisfies the predicate, false otherwise
        Throws:
        java.lang.Throwable - if an error occurs during evaluation
      • negate

        default CheckedPredicate<T> negate()
        Returns a predicate that represents the logical negation of this predicate.
        Returns:
        a new CheckedPredicate representing the negated condition
      • unchecked

        default java.util.function.Predicate<T> unchecked()
        Returns an unchecked Predicate that sneakily throws any exception encountered when testing a value.
        Returns:
        a Predicate that may throw any Throwable without declaring it