@FunctionalInterface public interface ThrowingFunction<T,R> extends Function<T,R>
ThrowingFunction<String, Integer> parse = Integer::parseInt;
Function<String, Optional<Integer>> safeParse = parse.fallbackTo(string -> null)
.andThen(Optional::ofNullable);
| Modifier and Type | Method and Description |
|---|---|
default <V> ThrowingFunction<T,V> |
andThen(ThrowingFunction<? super R,? extends V> after)
Returns a composed
ThrowingFunction that first applies this function to the argument, and then applies the after function to the result. |
default R |
apply(T argument)
Applies this function to the given argument.
|
R |
applyThrowing(T argument)
Applies this function to the given argument.
|
default <V> ThrowingFunction<V,R> |
compose(ThrowingFunction<? super V,? extends T> before)
Returns a composed
ThrowingFunction that first applies the before function to the argument, and then applies this function to the result. |
default Function<T,R> |
fallbackTo(Function<T,R> fallback)
Returns a
Function applying the given function to the argument if this function throws an exception. |
default Function<T,R> |
fallbackTo(Function<T,R> fallback,
Consumer<Exception> exceptionConsumer)
Returns a
Function applying the given function to the argument if this function throws an exception. |
default Function<T,R> |
orReturn(R value)
Returns a
Function returning the given value if this function throws an exception. |
default Function<T,R> |
orReturn(R value,
Consumer<Exception> exceptionConsumer)
Returns a
Function returning the given value if this function throws an exception. |
default ThrowingFunction<T,R> |
orThrow(Class<? extends RuntimeException> exceptionClass)
Returns a
ThrowingFunction throwing an exception of the given type if this function throws an exception. |
default ThrowingFunction<T,R> |
orThrow(Class<? extends RuntimeException> exceptionClass,
String message)
Returns a
ThrowingFunction throwing an exception of the given type if this function throws an exception. |
default ThrowingFunction<T,R> |
orTryWith(ThrowingFunction<? super T,? extends R> other)
Returns a
ThrowingFunction applying the given function to the argument if this function throws an exception. |
default ThrowingFunction<T,R> |
orTryWith(ThrowingFunction<? super T,? extends R> other,
Consumer<Exception> exceptionConsumer)
Returns a
ThrowingFunction applying the given function to the argument if this function throws an exception. |
default <V> ThrowingFunction<T,V> andThen(ThrowingFunction<? super R,? extends V> after)
ThrowingFunction that first applies this function to the argument, and then applies the after function to the result.IllegalArgumentException - if after is nulldefault R apply(T argument)
UncheckedException.R applyThrowing(T argument) throws Exception
Exceptiondefault <V> ThrowingFunction<V,R> compose(ThrowingFunction<? super V,? extends T> before)
ThrowingFunction that first applies the before function to the argument, and then applies this function to the result.IllegalArgumentException - if before is nulldefault Function<T,R> fallbackTo(Function<T,R> fallback)
Function applying the given function to the argument if this function throws an exception.IllegalArgumentException - if fallback is nulldefault Function<T,R> fallbackTo(Function<T,R> fallback, Consumer<Exception> exceptionConsumer)
Function applying the given function to the argument if this function throws an exception.IllegalArgumentException - if fallback is nulldefault Function<T,R> orReturn(R value)
Function returning the given value if this function throws an exception.default Function<T,R> orReturn(R value, Consumer<Exception> exceptionConsumer)
Function returning the given value if this function throws an exception.default ThrowingFunction<T,R> orThrow(Class<? extends RuntimeException> exceptionClass)
ThrowingFunction throwing an exception of the given type if this function throws an exception.
The original exception thrown by this function is the cause of the thrown exception.
The exception class must have a constructor accepting a single Throwable as an argument.
IllegalArgumentException - if exceptionClass is nulldefault ThrowingFunction<T,R> orThrow(Class<? extends RuntimeException> exceptionClass, String message)
ThrowingFunction throwing an exception of the given type if this function throws an exception.
The original exception thrown by this function is the cause of the thrown exception.
The exception class must have a constructor accepting String and Throwable as arguments.
IllegalArgumentException - if exceptionClass is nulldefault ThrowingFunction<T,R> orTryWith(ThrowingFunction<? super T,? extends R> other)
ThrowingFunction applying the given function to the argument if this function throws an exception.IllegalArgumentException - if other is nulldefault ThrowingFunction<T,R> orTryWith(ThrowingFunction<? super T,? extends R> other, Consumer<Exception> exceptionConsumer)
ThrowingFunction applying the given function to the argument if this function throws an exception.IllegalArgumentException - if other is null