public final class FunctionExtensions extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Functions.Function1<T,Boolean> |
and(Functions.Function1<? super T,Boolean> test,
Functions.Function1<? super T,Boolean> test2)
This method composes two predicate functions (Functions returning a
Boolean value). |
static <V,R> @NonNull Functions.Function0<V> |
andThen(@NonNull Functions.Function0<? extends R> before,
@NonNull Functions.Function1<? super R,? extends V> after)
Returns a composed function that first calls
before function to and
then applies the after function to the result. |
static <T> Functions.Function1<T,Boolean> |
negate(Functions.Function1<T,Boolean> test)
This method will wrap the given
test function in the returned function. |
static <T,V,R> @NonNull Functions.Function1<T,V> |
operator_doubleGreaterThan(@NonNull Functions.Function1<? super T,? extends R> self,
@NonNull Functions.Function1<? super R,? extends V> after)
Shortcut operator for
FunctionExtensions#andThen((T)=>R, (R)=>V) . |
static <T,V,R> @NonNull Functions.Function1<V,R> |
operator_doubleLessThan(@NonNull Functions.Function1<? super T,? extends R> self,
@NonNull Functions.Function1<? super V,? extends T> before)
Shortcut operator for
FunctionExtensions#compose((T)=>R, (V)=>T) |
static <T,V,R> R |
operator_tripleGreaterThan(@NonNull Pair<T,V> value,
@NonNull Functions.Function2<? super T,? super V,? extends R> function)
This extension operator is the "pipe forward" operator for value-pairs.
|
static <T,R> R |
operator_tripleGreaterThan(T value,
@NonNull Functions.Function1<? super T,? extends R> function)
This extension operator is the "pipe forward" operator.
|
static <T> Functions.Function1<T,Boolean> |
or(Functions.Function1<? super T,Boolean> test,
Functions.Function1<? super T,Boolean> test2)
This method composes two predicate functions (Functions returning a
Boolean value). |
public static <T,R> R operator_tripleGreaterThan(T value, @NonNull Functions.Function1<? super T,? extends R> function) throws NullPointerException
function
will be called with the given value
. The advantage
is that chained nested calls are represented as chains which can be easier to
read. E.g. the nested call c.apply(b.apply(a.apply(val)))
can be
represented like this: val >>> a >>> b >>> c
.T
- input value typeR
- return value typevalue
- a value that will piped into the function
. Meaning that
function
will be called with value
as its
parameter.function
- Will be called with value
Must not be null
.function
with value
NullPointerException
- if function
is nullpublic static <T,V,R> R operator_tripleGreaterThan(@NonNull Pair<T,V> value, @NonNull Functions.Function2<? super T,? super V,? extends R> function) throws NullPointerException
function
with the the two values of the pair as parameters
and return the resultT
- Type of key
of the input pairV
- Type of value
of the input pairR
- Type of the return valuevalue
- This parameter must not be null
.function
- the function to be invoked with the key
and value
of the given value
.function
.NullPointerException
- if either value
or function
is null@Pure public static <T,V,R> @NonNull Functions.Function1<V,R> operator_doubleLessThan(@NonNull Functions.Function1<? super T,? extends R> self, @NonNull Functions.Function1<? super V,? extends T> before)
FunctionExtensions#compose((T)=>R, (V)=>T)
T
- type of output value to before
and input value of self
V
- type of input value of before
and input value to the returned composed functionR
- type of output value of self
and return type of the returned composed functionself
- function that will be composed with before
.before
- function to be invoked before self
. The result of the
invocation will be passed to self
.before
and self
.@Pure public static <T,V,R> @NonNull Functions.Function1<T,V> operator_doubleGreaterThan(@NonNull Functions.Function1<? super T,? extends R> self, @NonNull Functions.Function1<? super R,? extends V> after)
FunctionExtensions#andThen((T)=>R, (R)=>V)
.T
- type of the input value of self
and input type to the returned concatenated functionV
- type of the return value of after
and return type of the returned concatenated functionR
- return type of self
and type of input value of after
self
- the function to apply before the after
function is appliedafter
- the function to apply after the before
function is appliedbefore
function
and then applies the self
function with the result of
before
@Pure public static <V,R> @NonNull Functions.Function0<V> andThen(@NonNull Functions.Function0<? extends R> before, @NonNull Functions.Function1<? super R,? extends V> after)
before
function to and
then applies the after
function to the result. If evaluation of
either function throws an exception, it is relayed to the caller of the
composed function.V
- the type of output of the after
function, and of the
composed function.R
- the return type of function before
and input to function
after
.before
- the function to apply before after
function is applied in
the returned composed function. The input to the composed function
will be passed to this function and the output will be forwarded
to function after
.after
- the function to be called after function before
taking
that functions output as an input in the returned composed
function. The output of this function will be the return value of
the composed function.after
functionNullPointerException
- if before
or after
is null
public static <T> Functions.Function1<T,Boolean> and(Functions.Function1<? super T,Boolean> test, Functions.Function1<? super T,Boolean> test2)
Boolean
value).
The composed function will first call test
with the given input value and then
will use a short circuit &&
operator on the result with the result of test2
applied on the input value. In pseudo code test(input) && test2(input)
. This means if
test
throws an exception, test2
will not be evaluated and the exception will
be thrown to the caller of the returned composed function. Since the operator is short circuiting,
test2
will not be called if test
returns false
.T
- input type to test
and test2
test
- function to be composed with test2
. Will be called on the left hand side of the &&
operator.test2
- function to be composed with test
. Will be called on the right hand side of the &&
operator.test
and test2
(called with its input value) with
the &&
operator.public static <T> Functions.Function1<T,Boolean> or(Functions.Function1<? super T,Boolean> test, Functions.Function1<? super T,Boolean> test2)
Boolean
value).
The composed function will first call test
with the given input value and then
will use a short circuiting ||
operator on the result with the result of test2
applied on the input value. In pseudo code test(input) || test2(input)
. This means if
test
throws an exception, test2
will not be evaluated and the exception will
be thrown to the caller of the returned composed function. Since the operator is short circuiting,
test2
will not be called if test
returns true
.T
- input type to test
and test2
test
- function to be composed with test2
. Will be called on the left hand side of the ||
operator.test2
- function to be composed with test
. Will be called on the right hand side of the ||
operator.test
and test2
(called with its input value) with
the ||
operator.public static <T> Functions.Function1<T,Boolean> negate(Functions.Function1<T,Boolean> test)
test
function in the returned function. The returned function
will call the wrapped function with its input value when applied, and return the negated return value
of test
. In pseudo code !test(input)
. If test
throws an exception, the exception
will be thrown to the caller of the returned function.T
- input type of test
test
- function to be wrapped by the returned function.test
and return the negated return value.Copyright © 2019. All rights reserved.