Interface ThrowingFunction<T,R>

Type Parameters:
T - the type of the input to the function
R - the type of the result of the function
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 ThrowingFunction<T,R>
Equivalent of Function whose apply(Object) method may throw a checked Exception.

This interface helps to avoid wrapping checked exceptions in runtime exceptions when using functional APIs.

  • Method Summary

    Modifier and Type
    Method
    Description
    default <V> ThrowingFunction<T,V>
    andThen(@NonNull ThrowingFunction<? super R,? extends V> 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 this function to the given argument.
    default <V> ThrowingFunction<V,R>
    compose(@NonNull ThrowingFunction<? super V,? extends T> before)
    Returns a composed function that first applies the before function to its input, and then applies this function to the result.
  • Method Details

    • apply

      R apply(T t) throws Exception
      Applies this function to the given argument.
      Parameters:
      t - the function argument
      Returns:
      the function result
      Throws:
      Exception - if unable to compute a result
    • compose

      default <V> ThrowingFunction<V,R> compose(@NonNull @NonNull ThrowingFunction<? super V,? extends T> before)
      Returns a composed function that first applies the before function to its input, and then applies this function to the result.
      Type Parameters:
      V - the type of input to the before function, and to the composed function
      Parameters:
      before - the function to apply before this function
      Returns:
      a composed function that first applies the before function and then this function
    • andThen

      default <V> ThrowingFunction<T,V> andThen(@NonNull @NonNull ThrowingFunction<? super R,? extends V> after)
      Returns a composed function that first applies this function to its input, and then applies the after function to the result.
      Type Parameters:
      V - the type of output of the after function, and of the composed function
      Parameters:
      after - the function to apply after this function
      Returns:
      a composed function that first applies this function and then the after function