Interface ThrowingFunction<T,​R>

  • Type Parameters:
    T - the type of the input to the function
    R - the type of the result of the function
    All Known Subinterfaces:
    ThrowingUnaryOperation<T>
    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 ThrowingFunction<T,​R>
    When you find yourself in a situation where you need to use a method ( that throws an exception) withing Lambda, this class is what you need to achieve your goal without Java complaining.

    The class Represents a function that accepts one argument and produces a result. whose functional method is apply(Object).

    Since:
    1.0
    Author:
    , Bobai Kato
    • Method Detail

      • unchecked

        @NotNull
        static <T,​R> @NotNull Function<T,​R> unchecked​(ThrowingFunction<T,​R> function)
        Uncheck method which will take operation that will throw Exception.
        Type Parameters:
        T - the type of the input to the function
        R - the type of the result of the function
        Parameters:
        function - Variable of ThrowingFunction
        Returns:
        A Function
      • apply

        R apply​(T t)
         throws Exception
        Applies this function to the given argument.
        Parameters:
        t - the function argument if Type T
        Returns:
        the function result
        Throws:
        Exception - any exception thrown when applying function
      • sneakyThrow

        @Contract(value="_ -> fail",
                  pure=true)
        static <T extends Exception,​R> R sneakyThrow​(Exception ex)
                                                    throws T extends Exception
        Sneak exception on function execution.
        Type Parameters:
        T - arg type
        R - return type
        Parameters:
        ex - exception throw on operation
        Returns:
        an exception
        Throws:
        T - arg type exception
        T extends Exception