/** * This method allows a Function which throws exceptions to be used in places which expects a Function. * * @param <T> Any Object. * @param <R> Any Object * @param <E> Any Exception. * @param function Function to apply for given arguments. * @return Any Object that result from the function passed. */ public static <T, R, E extends Exception> Function<T, R> rethrowFunction( FunctionWithExceptions<T, R, E> function) { return t -> { try { return function.apply(t); } catch (Exception exception) { throwAsUnchecked(exception); return null; } }; }
/** * This method allows a Function which throws exceptions to be used in places which expects a Function. * * @param <T> Any Object. * @param <R> Any Object * @param <E> Any Exception. * @param function Function to apply for given arguments. * @return Any Object that result from the function passed. */ public static <T, R, E extends Exception> Function<T, R> rethrowFunction( FunctionWithExceptions<T, R, E> function) { return t -> { try { return function.apply(t); } catch (Exception exception) { throwAsUnchecked(exception); return null; } }; }