Interface FailableFunction<T,​R,​E extends Exception>

  • Type Parameters:
    T - The type of the input
    R - The type of the output
    E - The exception type
    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 FailableFunction<T,​R,​E extends Exception>
    A function that may fail with a checked exception during the execution of the apply(..) method.
    Author:
    Eyal Schneider
    • Method Detail

      • apply

        R apply​(T v)
         throws E extends Exception
        Applies the function
        Parameters:
        v - the input argument
        Returns:
        the function result
        Throws:
        E - in case of an error
        E extends Exception
      • compose

        default <V> FailableFunction<V,​R,​E> compose​(FailableFunction<? super V,​? extends T,​E> before)
        Similar to Function.compose(..), but works with FailableFunction
        Type Parameters:
        V - The input type of the supplied function to be applied first
        Parameters:
        before - the function to apply before this function is applied
        Returns:
        a composed FailableFunction that first applies the before function and then applies this function
      • andThen

        default <V> FailableFunction<T,​V,​E> andThen​(FailableFunction<? super R,​? extends V,​E> after)
        Similar to Function.andThen(..), but works with FailableFunction
        Type Parameters:
        V - The output type of the supplied function
        Parameters:
        after - the FailableFunction to apply after this function is applied
        Returns:
        a composed function that first applies this function and then applies the after function
      • identity

        static <T,​E extends ExceptionFailableFunction<T,​T,​E> identity()
        Similar to Function.identity(), but returns a FailableFunction
        Type Parameters:
        T - The input/output type
        E - The error type
        Returns:
        a function that always returns its input argument.