- Type Parameters:
T
- The type of the input resultR
- The type of the output result
- 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 ResultMappingFunction<T,R>
extends Function<Result<T>,Result<R>>
Functional interface for mapping the type of a
This function is a more friendly variant of
Result
.This function is a more friendly variant of
Function<Result<T>, Result<R>>
.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
R> @NotNull ResultMappingFunction <T, R> Creates a new result mapping function that applies the given function to the result.
If the result is an error, the error is propagated to the output result and the function is not applied.static <T,
R> @NotNull ResultMappingFunction <T, R> throwable
(@NotNull ThrowableFunction<T, R, ? extends Throwable> function) Creates a new result mapping function that applies the given throwable function to the result.
If the result is an error, the error is propagated to the output result and the function is not applied.
If the function throws an exception, the exception is caught and the output result is an error with the exception message.
In all other cases, the function is applied to the result.
-
Method Details
-
direct
@NotNull static <T,R> @NotNull ResultMappingFunction<T,R> direct(@NotNull @NotNull Function<T, R> function) Creates a new result mapping function that applies the given function to the result.
If the result is an error, the error is propagated to the output result and the function is not applied.- Type Parameters:
T
- The type of the input resultR
- The type of the output result- Parameters:
function
- The function to apply to the result- Returns:
- The result mapping function
- Throws:
NullPointerException
- If the function is null
-
throwable
@NotNull static <T,R> @NotNull ResultMappingFunction<T,R> throwable(@NotNull @NotNull ThrowableFunction<T, R, ? extends Throwable> function) Creates a new result mapping function that applies the given throwable function to the result.
If the result is an error, the error is propagated to the output result and the function is not applied.
If the function throws an exception, the exception is caught and the output result is an error with the exception message.
In all other cases, the function is applied to the result.- Type Parameters:
T
- The type of the input resultR
- The type of the output result- Parameters:
function
- The throwable function to apply to the result- Returns:
- The result mapping function
- Throws:
NullPointerException
- If the throwable function is null
-
apply
-