Interface Functions.FunctionWithError<A,​B>

  • All Superinterfaces:
    Function<A,​B>
    Enclosing class:
    Functions

    public static interface Functions.FunctionWithError<A,​B>
    extends Function<A,​B>
    An extension of Function that allows functional code to throw an exception.

    If used in a context not expecting this class, the error will be caught, logged, and re-thrown.

    • Method Detail

      • apply

        default B apply​(A a)
        Handles the case where this object is used in a regular Stream API, which cannot handle errors.

        Logs the error and throws a runtime exception.

        Specified by:
        apply in interface Function<A,​B>
        Parameters:
        a - The input object of type A
        Returns:
        The output object of type B
      • applyWithError

        B applyWithError​(A object)
                  throws Throwable
        Implements a function transforming an object of type A to an object of type B.

        This function can throw an arbitrary error.

        Parameters:
        object - The input object
        Returns:
        The output object
        Throws:
        Throwable - if any errors occur
      • compose

        default <V> Functions.FunctionWithError<V,​Bcompose​(Function<? super V,​? extends A> before)
        Creates an error-friendly function composition that first translates from input type V to intermediate type A, then translates from A to B.

        B = f2(f1(V))

        Specified by:
        compose in interface Function<A,​B>
        Type Parameters:
        V - The input type of the ‘before’ function
        Parameters:
        before - The function to invoke before invoking this function
        Returns:
        The composed FunctionWithError