Interface MCRThrowFunction<T,R,E extends Throwable>

Type Parameters:
T - the type of the input to the function
R - the type of the result of the function
E - the exception that is throw by this 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 MCRThrowFunction<T,R,E extends Throwable>
Represents a function that accepts one argument and produces a result and throws an Exception.

Use toFunction() or toFunction(BiFunction, Class) to transform this MCRThrowFunction into a Function that can be handled throughout Java 8.

Since:
2015.12
  • Method Summary

    Modifier and Type
    Method
    Description
    default <V> MCRThrowFunction<T,V,E>
    andThen(MCRThrowFunction<? super R,? extends V,? extends E> 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> MCRThrowFunction<V,R,E>
    compose(MCRThrowFunction<? super V,? extends T,? extends E> before)
    Returns a composed function that first applies the before function to its input, and then applies this function to the result.
    default Function<T,R>
    Returns a Function that applies <T> and catches any exception and wraps it into a RuntimeException if needed.
    default Function<T,R>
    toFunction(BiFunction<T,E,R> throwableHandler, Class<? super E> exClass)
    Returns a function that catches <E> and forwards it to the throwableHandler together with the Exception.
  • Method Details

    • apply

      R apply(T t) throws E
      Applies this function to the given argument.
      Parameters:
      t - the function argument
      Returns:
      the function result
      Throws:
      E extends Throwable
    • compose

      default <V> MCRThrowFunction<V,R,E> compose(MCRThrowFunction<? super V,? extends T,? extends E> before)
      Returns a composed function that first applies the before function to its input, and then applies this function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
      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 is applied
      Returns:
      a composed function that first applies the before function and then applies this function
      Throws:
      NullPointerException - if before is null
      See Also:
    • andThen

      default <V> MCRThrowFunction<T,V,E> andThen(MCRThrowFunction<? super R,? extends V,? extends E> after)
      Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
      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 is applied
      Returns:
      a composed function that first applies this function and then applies the after function
      Throws:
      NullPointerException - if after is null
      See Also:
    • toFunction

      default Function<T,R> toFunction(BiFunction<T,E,R> throwableHandler, Class<? super E> exClass)
      Returns a function that catches <E> and forwards it to the throwableHandler together with the Exception. Use this method if you want to react on the certain Exceptions and return a result or rethrow a specific RuntimeExption.
      Parameters:
      throwableHandler - a BiFunction that handles original Input and caught Exception
      exClass - class of exception to catch
    • toFunction

      default Function<T,R> toFunction()
      Returns a Function that applies <T> and catches any exception and wraps it into a RuntimeException if needed. Use this if you just want no specific exception handling.