R - return type@FunctionalInterface
public interface Function0<R>
extends java.util.function.Supplier<R>
The standard Java equivalent is Supplier, but this
implementation is more extensible. As it is exending Supplier it can
be used anywhere where a supplier is used.
| Modifier and Type | Field and Description |
|---|---|
static Function0<java.lang.Object> |
ALWAYS_NULL
Function which always returns a
null object. |
| Modifier and Type | Method and Description |
|---|---|
static <T> Function0<T> |
alwaysNull()
Get a zero-argument function which always returns
null. |
default <T> Function0<T> |
andThen(java.util.function.Function<? super R,? extends T> after)
Get a chained function which first applies this function
and then the given function to the returned value.
|
default R |
apply()
Run the function.
|
static <T> Function0<T> |
from(java.util.function.Supplier<T> supplier)
Make a
Supplier usable as a Function0. |
default <P1> Function1<R,P1> |
ignore1()
Make this zero-argument function appear as a function with one ignored argument.
|
static <E extends java.lang.Exception,RR> |
nonFragile(FragileFunction0<? extends RR,E> fragileFunction)
Convert a 0-argument function which might throw a checked exception into
one which does throw an unchecked exception.
|
static <E extends java.lang.Exception,RR> |
nonFragile(FragileFunction0<? extends RR,E> fragileFunction,
RR fallback)
Convert a 0-argument function which might throw a checked exception into
one which will return a default value instead of throwing an exception.
|
static <E extends java.lang.Exception,RR> |
nonFragileX(FragileFunction0<? extends RR,E> fragileFunction,
java.util.function.Function<? super E,? extends RR> exceptionHandler)
Convert a 0-argument function which might throw a checked exception into
one for which you can decide what happens with the exception.
|
@NotNull static final Function0<java.lang.Object> ALWAYS_NULL
null object.
Use alwaysNull() instead as it handles the return type
transparently.default R apply()
@NotNull default <T> Function0<T> andThen(@NotNull java.util.function.Function<? super R,? extends T> after)
T - result type of returned functionafter - function to apply after this one@NotNull default <P1> Function1<R,P1> ignore1()
P1 - argument type of returned function, ignored@NotNull static <T> Function0<T> alwaysNull()
null.T - result type of returned functionnull@NotNull static <T> Function0<T> from(@NotNull java.util.function.Supplier<T> supplier)
T - supplier return typesupplier - supplierFunction0 view of the given supplier@NotNull static <E extends java.lang.Exception,RR> Function0<RR> nonFragile(@NotNull FragileFunction0<? extends RR,E> fragileFunction)
WrappedFragileException for any
checked exception thrown during apply().E - exception typeRR - result type of incoming and outgoing function.fragileFunction - function throwing a checked exception@NotNull static <E extends java.lang.Exception,RR> Function0<RR> nonFragile(@NotNull FragileFunction0<? extends RR,E> fragileFunction, RR fallback)
E - exception typeRR - result type of incoming and outgoing function.fragileFunction - function throwing a checked exceptionfallback - fallback returned when fragileFunction has thrown an exception@NotNull static <E extends java.lang.Exception,RR> Function0<RR> nonFragileX(@NotNull FragileFunction0<? extends RR,E> fragileFunction, @NotNull java.util.function.Function<? super E,? extends RR> exceptionHandler)
nonFragile(FragileFunction0))nonFragile(FragileFunction0, Object))E - exception typeRR - result type of incoming and outgoing function.fragileFunction - function throwing a checked exceptionexceptionHandler - exception handler. Its return value will be used as return value of the returned function.