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>
Function
withThrowable
- 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 theafter
throwable-function to the result.R
apply(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 thebefore
throwable-function to its input, and then applies this throwable-function to the result.default R
execute(T t)
Executes#apply(T)
withthe default exception handling
static <T,R>
Rexecute(T t, ThrowableFunction<T,R> function)
ExecutesThrowableFunction
withthe default exception handling
static <T,R>
Rexecute(T t, ThrowableFunction<T,R> function, java.util.function.BiFunction<T,java.lang.Throwable,R> exceptionHandler)
ExecutesThrowableFunction
with the customized exception handlingdefault R
execute(T t, java.util.function.BiFunction<T,java.lang.Throwable,R> exceptionHandler)
Executes#apply(T)
with the customized exception handlingdefault R
handleException(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 thebefore
throwable-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 thebefore
throwable-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
before
throwable-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 theafter
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 output of theafter
throwable-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
after
throwable-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.NullPointerException
ExecutesThrowableFunction
withthe 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.NullPointerException
- iffunction
isnull
-
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.NullPointerException
ExecutesThrowableFunction
with 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.NullPointerException
- iffunction
andexceptionHandler
isnull
-
-