Interface ResultingFunction<T,R>

Type Parameters:
T - The type of the input value
R - The type of the output result
All Superinterfaces:
Function<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 ResultingFunction<T,R> extends Function<T,Result<R>>
Functional interface for mapping a value to a result.
This function is a more friendly variant of Function<T, Result<R>>.
The main use case is to map a value to a result that may contain an error.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Result<R>
    apply(@UnknownNullability T value)
     
    static <T, R> @NotNull ResultingFunction<T,R>
    direct(@NotNull Function<T,R> function)
    Creates a new resulting function that applies the given function to the value.
    The output result is a success result with the output of the function as value.
    static <T, R> @NotNull ResultingFunction<T,R>
    throwable(@NotNull ThrowableFunction<T,R,? extends Throwable> function)
    Creates a new resulting function that applies the given throwable function to the value.
    If the function throws an exception, the output result is an error with the exception message.
    In all other cases, the output result is a success result with the output of the function as value.

    Methods inherited from interface java.util.function.Function

    andThen, compose
  • Method Details

    • direct

      @NotNull static <T, R> @NotNull ResultingFunction<T,R> direct(@NotNull @NotNull Function<T,R> function)
      Creates a new resulting function that applies the given function to the value.
      The output result is a success result with the output of the function as value.
      Type Parameters:
      T - The type of the input value
      R - The type of the output result
      Parameters:
      function - The function to apply to the value
      Returns:
      The resulting function
      Throws:
      NullPointerException - If the function is null
    • throwable

      @NotNull static <T, R> @NotNull ResultingFunction<T,R> throwable(@NotNull @NotNull ThrowableFunction<T,R,? extends Throwable> function)
      Creates a new resulting function that applies the given throwable function to the value.
      If the function throws an exception, the output result is an error with the exception message.
      In all other cases, the output result is a success result with the output of the function as value.
      Type Parameters:
      T - The type of the input value
      R - The type of the output result
      Parameters:
      function - The throwable function to apply to the value
      Returns:
      The resulting function
      Throws:
      NullPointerException - If the throwable function is null
    • apply

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