R
- return typeP
- parameter type@FunctionalInterface
public interface Function1<R,P>
extends java.util.function.Function<P,R>
This is basically the same as Function
,
but is more extensible. As it is extending Function
it
can be used anywhere as a replacement.
Modifier and Type | Method and Description |
---|---|
default <T> Function1<R,T> |
after(java.util.function.Function<? super T,? extends P> before)
Get a chained function which first applies the
given function and then this one.
|
default <T> Function1<T,P> |
andThen(java.util.function.Function<? super R,? extends T> after)
Get a chained function which first applies this function
and then the given function.
|
default R |
applyNonNull(P argument,
R fallback)
Apply this function if the argument is not
null , otherwise return the fallback. |
default R |
applyOrDefault(P argument,
R fallback)
Apply this function, but take care to create a fallback.
|
static <RR,PP> Function1<RR,PP> |
fallback(Function1<? extends RR,? super PP> func1,
Function1<? extends RR,? super PP> func2)
Get a function which is a combination of two functions
which calls the first function and returns its result.
|
static <RR,PP> Function1<RR,PP> |
fallback(java.util.function.Predicate<? super RR> validCheck,
Function1<? extends RR,? super PP> func1,
Function1<? extends RR,? super PP> func2)
Get a function which is a combination of two functions
which calls the first function and returns its result.
|
static <TT,PP,EE extends java.lang.Exception> |
from(FragileFunction1<TT,EE,PP> ff)
Create a normal function from a fragile function.
|
static <RR,PP> Function1<RR,PP> |
from(java.util.function.Function<PP,RR> func)
Make a
Function usable as a Function1 . |
static <E extends java.lang.Exception,RR,PP> |
nonFragile(FragileFunction1<? extends RR,E,? super PP> fragileFunction)
Convert a 1-argument function which might throw a checked exception into
one which does throw an unchecked exception.
|
static <E extends java.lang.Exception,RR,PP> |
nonFragile(FragileFunction1<? extends RR,E,? super PP> fragileFunction,
RR fallback)
Convert a 1-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,PP> |
nonFragileX(FragileFunction1<? extends RR,E,? super PP> fragileFunction,
java.util.function.BiFunction<? super E,? super PP,? extends RR> exceptionHandler)
Convert a 1-argument function which might throw a checked exception into
one for which you can decide what happens with the exception.
|
default Function0<R> |
partial(P argument)
Create a zero argument function from this one by applying a constant argument.
|
default Function1<R,P> |
withFallback(Function1<? extends R,? super P> fallback)
Get a function which calls a fallback function if this function
returns
null . |
@NotNull default R applyOrDefault(P argument, @NotNull R fallback)
Function.apply(Object)
returns null
.argument
- argument of this functionfallback
- fallback value returned if function returns null
Function.apply(Object)
, or fallback
if the result was null
applyNonNull(Object, Object)
default R applyNonNull(P argument, R fallback)
null
, otherwise return the fallback.
The difference to applyOrDefault(Object, Object)
is that this function is not
applied when argument
is null
.
Using this invocation it is guaranteed that Function.apply(Object)
will always be called with
a non-null argument.
argument
- argument of this functionfallback
- fallback returned if argument
is null
argument
,
or fallback
if argument
is null@NotNull default Function1<R,P> withFallback(@NotNull Function1<? extends R,? super P> fallback)
null
.fallback
- fallback function called if this function returns null
for a given parameterfallback(Function1, Function1)
,
applyOrDefault(Object, Object)
@NotNull default Function0<R> partial(P argument)
argument
- constant argument@NotNull default <T> Function1<R,T> after(@NotNull java.util.function.Function<? super T,? extends P> before)
T
- parameter type of returned functionbefore
- function to apply first@NotNull default <T> Function1<T,P> andThen(@NotNull java.util.function.Function<? super R,? extends T> after)
@NotNull static <TT,PP,EE extends java.lang.Exception> Function1<TT,PP> from(@NotNull FragileFunction1<TT,EE,PP> ff)
EvaluationException
(an unchecked runtime exception) with
the original exception as the cause.TT
- result typePP
- parameter typeEE
- exception typeff
- fragile function@NotNull static <RR,PP> Function1<RR,PP> from(@NotNull java.util.function.Function<PP,RR> func)
Function
usable as a Function1
.RR
- result typePP
- parameter typefunc
- standard functionFunction1
view of the given function@NotNull static <RR,PP> Function1<RR,PP> fallback(@NotNull Function1<? extends RR,? super PP> func1, @NotNull Function1<? extends RR,? super PP> func2)
null
it will
call the second function and return its result.PP
- parameter type of returned function, which is the most extending
type of both func1
's parameter type and func2
's
parameter type, so if neither type is extending the other this method
will not compileRR
- result type of returned function, which is the most restricting type
of of both func1
's result type and func2
's
result type, so if neither type is extending the other this method
will not compilefunc1
- first functionfunc2
- second functionnull
fallback(Predicate, Function1, Function1)
@NotNull static <RR,PP> Function1<RR,PP> fallback(@NotNull java.util.function.Predicate<? super RR> validCheck, @NotNull Function1<? extends RR,? super PP> func1, @NotNull Function1<? extends RR,? super PP> func2)
PP
- parameter type of returned function, which is the most extending
type of both func1
's parameter type and func2
's
parameter type, so if neither type is extending the other this method
will not compileRR
- result type of returned function, which is the most restricting type
of of both func1
's result type and func2
's
result type, so if neither type is extending the other this method
will not compilevalidCheck
- check which determines the validity of the return of
func1
, if the check returns false
func2
will be used to calculate the result
of the returned functionfunc1
- first functionfunc2
- second functionfallbackCheck
identifies as invalid@NotNull static <E extends java.lang.Exception,RR,PP> Function1<RR,PP> nonFragile(@NotNull FragileFunction1<? extends RR,E,? super PP> fragileFunction)
WrappedFragileException
for any
checked exception thrown during Function.apply(Object)
.E
- exception typeRR
- result type of incoming and outgoing function.PP
- type of parameter of both functionsfragileFunction
- function throwing a checked exceptionWrappedFragileException
- wrapping the original exception from fragileFunction
@NotNull static <E extends java.lang.Exception,RR,PP> Function1<RR,PP> nonFragile(@NotNull FragileFunction1<? extends RR,E,? super PP> fragileFunction, RR fallback)
E
- exception typeRR
- result type of incoming and outgoing function.PP
- type of parameter of both functionsfragileFunction
- function throwing a checked exceptionfallback
- fallback returned when fragileFunction
has thrown an exception@NotNull static <E extends java.lang.Exception,RR,PP> Function1<RR,PP> nonFragileX(@NotNull FragileFunction1<? extends RR,E,? super PP> fragileFunction, @NotNull java.util.function.BiFunction<? super E,? super PP,? extends RR> exceptionHandler)
nonFragile(FragileFunction1)
)nonFragile(FragileFunction1, Object)
)E
- exception typeRR
- result type of incoming and outgoing function.PP
- type of parameter of both functionsfragileFunction
- function throwing a checked exceptionexceptionHandler
- exception handler. Its return value will be used as return value of the returned function.