Interface ResultMappingFunction<T,R>

Type Parameters:
T - The type of the input result
R - The type of the output result
All Superinterfaces:
Function<Result<T>,Result<R>>
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 Result.
This function is a more friendly variant of Function<Result<T>, Result<R>>.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Result<R>
    apply(@NotNull Result<T> input)
     
    static <T, R> @NotNull ResultMappingFunction<T,R>
    direct(@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.
    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.

    Methods inherited from interface java.util.function.Function

    andThen, compose
  • 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 result
      R - 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 result
      R - 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

      @NotNull @NotNull Result<R> apply(@NotNull @NotNull Result<T> input)
      Specified by:
      apply in interface Function<T,R>