Class ThrowableOptional


  • public final class ThrowableOptional
    extends Object
    ThrowableOptional is a utility class that enables the possibility to use the Optional with functions that can throw exceptions
    Author:
    brandonfl
    • Method Detail

      • of

        public static <T> Optional<T> of​(Callable<T> function)
        ThrowableOptional of callable functions Exemple : ThrowableOptional.of(() -> Long.parseLong(value))
        Parameters:
        function - a callable function
        Returns:
        Optional of the throwable function
      • of

        public static <T,​R> Optional<R> of​(java.util.function.Function<T,​R> function,
                                                 T parameter)
        ThrowableOptional of functions with one parameter Exemple : ThrowableOptional.of(Long::parseLong, value)
        Type Parameters:
        T - Type of the parameter
        R - Result of the function
        Parameters:
        function - the function call
        parameter - the parameter for the function
        Returns:
        Optional of the throwable function