Package io.microsphere.lang.function
Interface ThrowableFunction<T,R>
-
- Type Parameters:
T- the source typeR- the return 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 ThrowableFunction<T,R>FunctionwithThrowable- Since:
- 1.0.0
- See Also:
Function,Throwable
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V> ThrowableFunction<T,V>andThen(ThrowableFunction<? super R,? extends V> after)Returns a composed throwable-function that first applies this throwable-function to its input, and then applies theafterthrowable-function to the result.Rapply(T t)Applies this function to the given argument.default <V> ThrowableFunction<V,R>compose(ThrowableFunction<? super V,? extends T> before)Returns a composed throwable-function that first applies thebeforethrowable-function to its input, and then applies this throwable-function to the result.default Rexecute(T t)Executes#apply(T)withthe default exception handlingstatic <T,R>
Rexecute(T t, ThrowableFunction<T,R> function)ExecutesThrowableFunctionwiththe default exception handlingstatic <T,R>
Rexecute(T t, ThrowableFunction<T,R> function, java.util.function.BiFunction<T,java.lang.Throwable,R> exceptionHandler)ExecutesThrowableFunctionwith the customized exception handlingdefault Rexecute(T t, java.util.function.BiFunction<T,java.lang.Throwable,R> exceptionHandler)Executes#apply(T)with the customized exception handlingdefault RhandleException(T t, java.lang.Throwable failure)Handle any exception that the#apply(T)method throws
-
-
-
Method Detail
-
apply
R apply(T t) throws java.lang.Throwable
Applies this function to the given argument.- Parameters:
t- the function argument- Returns:
- the function result
- Throws:
java.lang.Throwable- if met with any error
-
execute
default R execute(T t) throws java.lang.RuntimeException
Executes#apply(T)withthe default exception handling- Parameters:
t- the function argument- Returns:
- the function result
- Throws:
java.lang.RuntimeException
-
execute
default R execute(T t, java.util.function.BiFunction<T,java.lang.Throwable,R> exceptionHandler) throws java.lang.RuntimeException
Executes#apply(T)with the customized exception handling- Parameters:
t- the function argumentexceptionHandler- the handler to handle the function argument and the exception that the#apply(T)method throws- Returns:
- the function result
- Throws:
java.lang.RuntimeException
-
handleException
default R handleException(T t, java.lang.Throwable failure)
Handle any exception that the#apply(T)method throws- Parameters:
t- the value to be consumedfailure- the instance ofThrowable
-
compose
default <V> ThrowableFunction<V,R> compose(ThrowableFunction<? super V,? extends T> before)
Returns a composed throwable-function that first applies thebeforethrowable-function to its input, and then applies this throwable-function to the result. If evaluation of either throwable-function throws an exception, it is relayed to the caller of the composed throwable-function.- Type Parameters:
V- the type of input to thebeforethrowable-function, and to the composed throwable-function- Parameters:
before- the throwable-function to apply before this throwable-function is applied- Returns:
- a composed throwable-function that first applies the
beforethrowable-function and then applies this throwable-function - Throws:
java.lang.NullPointerException- if before is null- See Also:
andThen(ThrowableFunction)
-
andThen
default <V> ThrowableFunction<T,V> andThen(ThrowableFunction<? super R,? extends V> after)
Returns a composed throwable-function that first applies this throwable-function to its input, and then applies theafterthrowable-function to the result. If evaluation of either throwable-function throws an exception, it is relayed to the caller of the composed throwable-function.- Type Parameters:
V- the type of output of theafterthrowable-function, and of the composed throwable-function- Parameters:
after- the throwable-function to apply after this throwable-function is applied- Returns:
- a composed throwable-function that first applies this throwable-function and then
applies the
afterthrowable-function - Throws:
java.lang.NullPointerException- if after is null- See Also:
compose(ThrowableFunction)
-
execute
static <T,R> R execute(T t, ThrowableFunction<T,R> function) throws java.lang.IllegalArgumentExceptionExecutesThrowableFunctionwiththe default exception handling- Type Parameters:
T- the source typeR- the return type- Parameters:
t- the throwable-function argumentfunction-ThrowableFunction- Returns:
- the result after execution
- Throws:
java.lang.IllegalArgumentException- iffunctionisnull
-
execute
static <T,R> R execute(T t, ThrowableFunction<T,R> function, java.util.function.BiFunction<T,java.lang.Throwable,R> exceptionHandler) throws java.lang.IllegalArgumentExceptionExecutesThrowableFunctionwith the customized exception handling- Type Parameters:
T- the source typeR- the return type- Parameters:
t- the function argumentexceptionHandler- the handler to handle the function argument and the exception that the#apply(T)method throwsfunction-ThrowableFunction- Returns:
- the result after execution
- Throws:
java.lang.IllegalArgumentException- iffunctionandexceptionHandlerisnull
-
-