Interface SafeFunction<T,R>

Type Parameters:
T - the type of the input
R - the type of the 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 SafeFunction<T,R>
A Function that can throw a checked exception.
  • Method Details

    • constant

      static <T,R> SafeFunction<T,R> constant(R r)
      A SafeFunction that always returns the same value, ignoring the input.
      Type Parameters:
      T - the type of the input
      R - the type of the result
      Parameters:
      r - the value to return
      Returns:
      a SafeFunction that always returns the given value
    • of

      static <T,R> SafeFunction<T,R> of(Function<T,R> function)
      Type Parameters:
      T - the type of the input
      R - the type of the result
      Parameters:
      function - the function to wrap
      Returns:
      a SafeFunction that delegates to the given function
    • apply

      R apply(T t) throws Exception
      Apply the function, possibly throwing an exception.
      Parameters:
      t - the input
      Returns:
      the result
      Throws:
      Exception
    • applyCatching

      default Result<R> applyCatching(T t)
      Apply the function, catching any exceptions and wrapping them in a Result
      Parameters:
      t - the input
      Returns:
      the result
    • asFunction

      default Function<T,R> asFunction()
      Turn this SafeFunction into a Function that sneaky throws any exceptions.
      Returns:
      a Function that sneaky throws any exceptions