Interface ThrowableFunction<T,R,X extends Throwable>

Type Parameters:
T - The type of the argument
R - The return type
X - The exception that can be thrown
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 ThrowableFunction<T,R,X extends Throwable>
Functional interface that takes an argument and returns a value.
The FunctionalInterface method is apply(Object).
The class is equivalent to Function, but the functional method can throw a checked exception.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <S> @NotNull ThrowableFunction<T,S,X>
    andThen(@NotNull ThrowableFunction<? super R,? extends S,X> after)
    Returns a composed function that first applies this function to its input,
    and then applies the after function to the result.
    apply(T t)
    Applies the argument to the function and returns the result.
    static <T, R> @NotNull Function<T,R>
    caught(@NotNull ThrowableFunction<T,R,? extends Throwable> function)
    Converts a throwable function into a function that throws a runtime exception when an exception is thrown.
  • Method Details

    • caught

      @NotNull static <T, R> @NotNull Function<T,R> caught(@NotNull @NotNull ThrowableFunction<T,R,? extends Throwable> function)
      Converts a throwable function into a function that throws a runtime exception when an exception is thrown.
      Type Parameters:
      T - The argument type
      R - The return type
      Parameters:
      function - The throwable function
      Returns:
      A caught function
      Throws:
      NullPointerException - If the throwable function is null
    • apply

      R apply(T t) throws X
      Applies the argument to the function and returns the result.
      Parameters:
      t - The argument
      Returns:
      The result
      Throws:
      X - The exception that can be thrown
    • andThen

      @NotNull default <S> @NotNull ThrowableFunction<T,S,X> andThen(@NotNull @NotNull ThrowableFunction<? super R,? extends S,X> after)
      Returns a composed function that first applies this function to its input,
      and then applies the after function to the result.
      Type Parameters:
      S - The type of the output of the after function, and of the composed function
      Parameters:
      after - The function to apply after this function is applied
      Returns:
      The composed throwable function
      Throws:
      NullPointerException - If the after function is null