public final class PairExtensions extends Object
Pair
class.Modifier and Type | Method and Description |
---|---|
static <K,V,R> R |
combine(Pair<K,V> pair,
Functions.Function2<? super K,? super V,? extends R> combiner)
Will call the
combiner with the key and the value of pair and returns
the result of the combiner call. |
static <K,V> Pair<K,V> |
operator_doubleArrow(Pair<K,V> pair,
Procedures.Procedure2<? super K,? super V> consumer)
Will call the given
consumer with the key and value extracted from pair . |
static <K,V,R> Optional<R> |
safeCombine(Pair<K,V> pair,
Functions.Function2<? super K,? super V,? extends R> combiner)
If
pair , or key or value of the given pair is null , this function returns an empty Optional . |
public static <K,V> Pair<K,V> operator_doubleArrow(Pair<K,V> pair, Procedures.Procedure2<? super K,? super V> consumer)
consumer
with the key and value extracted from pair
.
If the given consumer
throws an exception it will be thrown out of this method.K
- Type of key element of pair
V
- Type of value element of pair
pair
- the Pair from which key and value are taken and passed to consumer
.consumer
- will be called with key and value from pair
pair
public static <K,V,R> R combine(Pair<K,V> pair, Functions.Function2<? super K,? super V,? extends R> combiner)
combiner
with the key and the value of pair
and returns
the result of the combiner
call. This function can be used as a flatMap
function by returning a new Pair
.K
- Type of key element of pair
V
- Type of value element of pair
R
- Type of the result of the combination of key and valuepair
- the Pair from which key and value are taken and passed to combiner
combiner
- the function to be called with key and value from pair
combiner
.public static <K,V,R> Optional<R> safeCombine(Pair<K,V> pair, Functions.Function2<? super K,? super V,? extends R> combiner)
pair
, or key or value of the given pair
is null
, this function returns an empty Optional
.
Otherwise the combiner
will be called with the key and the value of pair
and returns
the result of the combiner
call wrapped in an Optional
. If the result of combiner
is null
an empty Optional will be returned.K
- Type of key element of pair
V
- Type of value element of pair
R
- Type of the result of the combination of key and valuepair
- the Pair from which key and value are taken and passed to combiner
if none of them is null
.combiner
- the function to be called with non-null key and value from pair
combiner
wrapped in an OptionalCopyright © 2019. All rights reserved.