K
- Key typeV
- Value typepublic interface Map<K,V> extends Traversable<Tuple2<K,V>>, Function1<K,V>
Map
interface.
Basic operations:
containsKey(Object)
containsValue(Object)
get(Object)
keySet()
merge(Map)
merge(Map, BiFunction)
put(Object, Object)
put(Tuple2)
put(Object, Object, BiFunction)
put(Tuple2, BiFunction)
values()
λ.Memoized
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID |
Modifier and Type | Method and Description |
---|---|
default V |
apply(K key)
Applies this function to one argument and returns the result.
|
<K2,V2> Map<K2,V2> |
bimap(Function<? super K,? extends K2> keyMapper,
Function<? super V,? extends V2> valueMapper)
Maps this
Map to a new Map with different component type by applying a function to its elements. |
Tuple2<V,? extends Map<K,V>> |
computeIfAbsent(K key,
Function<? super K,? extends V> mappingFunction)
If the specified key is not already associated with a value,
attempts to compute its value using the given mapping
function and enters it into this map.
|
Tuple2<Option<V>,? extends Map<K,V>> |
computeIfPresent(K key,
BiFunction<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key is present, attempts to
compute a new mapping given the key and its current mapped value.
|
default boolean |
contains(Tuple2<K,V> element)
Shortcut for
exists(e -> Objects.equals(e, element)) , tests if the given element is contained. |
boolean |
containsKey(K key)
Returns
true if this map contains a mapping for the specified key. |
default boolean |
containsValue(V value)
Returns
true if this map maps one or more keys to the
specified value. |
Map<K,V> |
distinct()
Returns a new version of this which contains no duplicates.
|
Map<K,V> |
distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Returns a new version of this which contains no duplicates.
|
<U> Map<K,V> |
distinctBy(Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
Map<K,V> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
Map<K,V> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
Map<K,V> |
dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Drops elements until the predicate holds for the current element.
|
Map<K,V> |
dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Drops elements while the predicate holds for the current element.
|
static <K,V> Tuple2<K,V> |
entry(K key,
V value)
Convenience factory method to create a key/value pair.
|
Map<K,V> |
filter(BiPredicate<? super K,? super V> predicate)
Returns a new Map consisting of all elements which satisfy the given predicate.
|
Map<K,V> |
filter(Predicate<? super Tuple2<K,V>> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
Map<K,V> |
filterKeys(Predicate<? super K> predicate)
Returns a new Map consisting of all elements with keys which satisfy the given predicate.
|
Map<K,V> |
filterValues(Predicate<? super V> predicate)
Returns a new Map consisting of all elements with values which satisfy the given predicate.
|
<K2,V2> Map<K2,V2> |
flatMap(BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
FlatMaps this
Map to a new Map with different component type. |
default <U> Seq<U> |
flatMap(Function<? super Tuple2<K,V>,? extends Iterable<? extends U>> mapper)
Flat-maps this entries to a sequence of values.
|
default <U> U |
foldRight(U zero,
BiFunction<? super Tuple2<K,V>,? super U,? extends U> f)
Folds this elements from the right, starting with
zero and successively calling combine . |
default void |
forEach(BiConsumer<K,V> action)
Performs an action on key, value pair.
|
Option<V> |
get(K key)
Returns the
Some of value to which the specified key
is mapped, or None if this map contains no mapping for the key. |
V |
getOrElse(K key,
V defaultValue)
Returns the value associated with a key, or a default value if the key is not contained in the map.
|
<C> Map<C,? extends Map<K,V>> |
groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends Map<K,V>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
default boolean |
hasDefiniteSize()
Checks if this Traversable is known to have a finite size.
|
Map<K,V> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<? extends Map<K,V>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
default boolean |
isDistinct()
Checks if this Traversable may consist of distinct elements only.
|
default boolean |
isTraversableAgain()
Checks if this Traversable can be repeatedly traversed.
|
Iterator<Tuple2<K,V>> |
iterator()
An iterator by means of head() and tail().
|
Set<K> |
keySet()
Returns the keys contained in this map.
|
default int |
length()
Computes the number of elements of this Traversable.
|
default Function1<K,Option<V>> |
lift()
Turns this map into a plain function returning an Option result.
|
<K2,V2> Map<K2,V2> |
map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Maps the entries of this
Map to form a new Map . |
default <U> Seq<U> |
map(Function<? super Tuple2<K,V>,? extends U> mapper)
Maps the
Map entries to a sequence of values. |
<K2> Map<K2,V> |
mapKeys(Function<? super K,? extends K2> keyMapper)
Maps the keys of this
Map while preserving the corresponding values. |
<K2> Map<K2,V> |
mapKeys(Function<? super K,? extends K2> keyMapper,
BiFunction<? super V,? super V,? extends V> valueMerge)
Maps the keys of this
Map while preserving the corresponding values and applying a value merge function on collisions. |
<V2> Map<K,V2> |
mapValues(Function<? super V,? extends V2> valueMapper)
Maps the values of this
Map while preserving the corresponding keys. |
Map<K,V> |
merge(Map<? extends K,? extends V> that)
Creates a new map which by merging the entries of
this map and that map. |
<U extends V> |
merge(Map<? extends K,U> that,
BiFunction<? super V,? super U,? extends V> collisionResolution)
Creates a new map which by merging the entries of
this map and that map. |
static <K,V> Map<K,V> |
narrow(Map<? extends K,? extends V> map)
Narrows a widened
Map<? extends K, ? extends V> to Map<K, V>
by performing a type-safe cast. |
Tuple2<? extends Map<K,V>,? extends Map<K,V>> |
partition(Predicate<? super Tuple2<K,V>> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct tarversables
according to a predicate. |
Map<K,V> |
peek(Consumer<? super Tuple2<K,V>> action)
Performs the given
action on the first element if this is an eager implementation. |
<U extends V> |
put(K key,
U value,
BiFunction<? super V,? super U,? extends V> merge)
Associates the specified value with the specified key in this map.
|
Map<K,V> |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
Map<K,V> |
put(Tuple2<? extends K,? extends V> entry)
Convenience method for
put(entry._1, entry._2) . |
<U extends V> |
put(Tuple2<? extends K,U> entry,
BiFunction<? super V,? super U,? extends V> merge)
Convenience method for
put(entry._1, entry._2, merge) . |
Map<K,V> |
remove(K key)
Removes the mapping for a key from this map if it is present.
|
Map<K,V> |
removeAll(BiPredicate<? super K,? super V> predicate)
Returns a new Map consisting of all elements which do not satisfy the given predicate.
|
Map<K,V> |
removeAll(Iterable<? extends K> keys)
Removes the mapping for a key from this map if it is present.
|
Map<K,V> |
removeKeys(Predicate<? super K> predicate)
Returns a new Map consisting of all elements with keys which do not satisfy the given predicate.
|
Map<K,V> |
removeValues(Predicate<? super V> predicate)
Returns a new Map consisting of all elements with values which do not satisfy the given predicate.
|
Map<K,V> |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for the specified key only if currently mapped to the specified value.
|
Map<K,V> |
replace(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
Map<K,V> |
replaceAll(BiFunction<? super K,? super V,? extends V> function)
Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
|
Map<K,V> |
replaceAll(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces all occurrences of the given currentElement with newElement.
|
Map<K,V> |
replaceValue(K key,
V value)
Replaces the entry for the specified key only if it is currently mapped to some value.
|
Map<K,V> |
retainAll(Iterable<? extends Tuple2<K,V>> elements)
Keeps all occurrences of the given elements from this.
|
Map<K,V> |
scan(Tuple2<K,V> zero,
BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Computes a prefix scan of the elements of the collection.
|
default <U> Seq<U> |
scanLeft(U zero,
BiFunction<? super U,? super Tuple2<K,V>,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going left to right.
|
default <U> Seq<U> |
scanRight(U zero,
BiFunction<? super Tuple2<K,V>,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going right to left.
|
int |
size()
Computes the number of elements of this Traversable.
|
Iterator<? extends Map<K,V>> |
sliding(int size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(int, int) . |
Iterator<? extends Map<K,V>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<? extends Map<K,V>,? extends Map<K,V>> |
span(Predicate<? super Tuple2<K,V>> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the given
predicate and the second element is the remainder. |
default Spliterator<Tuple2<K,V>> |
spliterator() |
Map<K,V> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<? extends Map<K,V>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
Map<K,V> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
Map<K,V> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
Map<K,V> |
takeUntil(Predicate<? super Tuple2<K,V>> predicate)
Takes elements until the predicate holds for the current element.
|
Map<K,V> |
takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Takes elements while the predicate holds for the current element.
|
Map<K,V> |
toJavaMap()
Converts this Javaslang
Map to a java.util.Map while preserving characteristics
like insertion order (LinkedHashMap ) and sort order (SortedMap ). |
default <U> U |
transform(Function<? super Map<K,V>,? extends U> f)
Transforms this
Map . |
default <U> Seq<U> |
traverse(BiFunction<K,V,? extends U> mapper) |
default Tuple2<Seq<K>,Seq<V>> |
unzip() |
default <T1,T2> Tuple2<Seq<T1>,Seq<T2>> |
unzip(BiFunction<? super K,? super V,Tuple2<? extends T1,? extends T2>> unzipper) |
default <T1,T2> Tuple2<Seq<T1>,Seq<T2>> |
unzip(Function<? super Tuple2<K,V>,Tuple2<? extends T1,? extends T2>> unzipper)
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct
sets.
|
default <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> |
unzip3(BiFunction<? super K,? super V,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper) |
default <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> |
unzip3(Function<? super Tuple2<K,V>,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct
sets.
|
Seq<V> |
values() |
default Function1<K,V> |
withDefault(Function<? super K,? extends V> defaultFunction)
Turns this map from a partial function into a total function that
returns a value computed by defaultFunction for all keys
absent from the map.
|
default Function1<K,V> |
withDefaultValue(V defaultValue)
Turns this map from a partial function into a total function that
returns defaultValue for all keys absent from the map.
|
default <U> Seq<Tuple2<Tuple2<K,V>,U>> |
zip(Iterable<? extends U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
default <U> Seq<Tuple2<Tuple2<K,V>,U>> |
zipAll(Iterable<? extends U> that,
Tuple2<K,V> thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
default <U,R> Seq<R> |
zipWith(Iterable<? extends U> that,
BiFunction<? super Tuple2<K,V>,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
default Seq<Tuple2<Tuple2<K,V>,Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
default <U> Seq<U> |
zipWithIndex(BiFunction<? super Tuple2<K,V>,? super Integer,? extends U> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
average, containsAll, count, existsUnique, find, findLast, foldLeft, get, hash, head, headOption, isEmpty, isOrdered, isSingleValued, last, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, sum
fold, reduce, reduceOption
collect, collect, corresponds, eq, equals, exists, forAll, forEach, getOption, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, hashCode, narrow, out, out, stderr, stdout, stringPrefix, toArray, toCharSeq, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStack, toStream, toString, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
andThen, arity, compose, constant, curried, identity, lift, liftTry, memoized, of, reversed, tupled
isMemoized
static final long serialVersionUID
static <K,V> Map<K,V> narrow(Map<? extends K,? extends V> map)
Map<? extends K, ? extends V>
to Map<K, V>
by performing a type-safe cast. This is eligible because immutable/read-only
collections are covariant.K
- Key typeV
- Value typemap
- A Map
.map
instance as narrowed type Map<K, V>
.static <K,V> Tuple2<K,V> entry(K key, V value)
If imported statically, this method allows to create a Map
with arbitrary entries in a readable and
type-safe way, e.g.:
HashMap.ofEntries(
entry(k1, v1),
entry(k2, v2),
entry(k3, v3)
);
K
- Key typeV
- Value typekey
- the entry's keyvalue
- the entry's valuedefault V apply(K key)
Function1
<K2,V2> Map<K2,V2> bimap(Function<? super K,? extends K2> keyMapper, Function<? super V,? extends V2> valueMapper)
Map
to a new Map
with different component type by applying a function to its elements.K2
- key's component type of the map resultV2
- value's component type of the map resultkeyMapper
- a Function
that maps the keys of type K
to keys of type K2
valueMapper
- a Function
that the values of type V
to values of type V2
Map
NullPointerException
- if keyMapper
or valueMapper
is nulldefault boolean contains(Tuple2<K,V> element)
Value
exists(e -> Objects.equals(e, element))
, tests if the given element
is contained.Tuple2<V,? extends Map<K,V>> computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
key
- key whose presence in this map is to be testedmappingFunction
- mapping functionTuple2
of current or modified map and existing or computed value associated with the specified keyTuple2<Option<V>,? extends Map<K,V>> computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
key
- key whose presence in this map is to be testedremappingFunction
- remapping functionTuple2
of current or modified map and the Some
of the value associated
with the specified key, or None
if noneboolean containsKey(K key)
true
if this map contains a mapping for the specified key.key
- key whose presence in this map is to be testedtrue
if this map contains a mapping for the specified keydefault boolean containsValue(V value)
true
if this map maps one or more keys to the
specified value. This operation will require time linear in the map size.value
- value whose presence in this map is to be testedtrue
if this map maps one or more keys to the
specified valueMap<K,V> filter(BiPredicate<? super K,? super V> predicate)
predicate
- the predicate used to test elementsNullPointerException
- if predicate
is nullMap<K,V> filterKeys(Predicate<? super K> predicate)
predicate
- the predicate used to test keys of elementsNullPointerException
- if predicate
is nullMap<K,V> filterValues(Predicate<? super V> predicate)
predicate
- the predicate used to test values of elementsNullPointerException
- if predicate
is null<K2,V2> Map<K2,V2> flatMap(BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
Map
to a new Map
with different component type.K2
- key's component type of the mapped Map
V2
- value's component type of the mapped Map
mapper
- A mapperMap
.NullPointerException
- if mapper
is nulldefault <U> Seq<U> flatMap(Function<? super Tuple2<K,V>,? extends Iterable<? extends U>> mapper)
Please use flatMap(BiFunction)
if the result should be a Map
flatMap
in interface Traversable<Tuple2<K,V>>
U
- Component typemapper
- A mapperdefault <U> U foldRight(U zero, BiFunction<? super Tuple2<K,V>,? super U,? extends U> f)
Foldable
zero
and successively calling combine
.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
default void forEach(BiConsumer<K,V> action)
action
- A BiConsumer
NullPointerException
- if action
is nullOption<V> get(K key)
Some
of value to which the specified key
is mapped, or None
if this map contains no mapping for the key.key
- the key whose associated value is to be returnedSome
of value to which the specified key
is mapped, or None
if this map contains no mapping
for the keyV getOrElse(K key, V defaultValue)
key
- the keydefaultValue
- a default valuedefault boolean hasDefiniteSize()
Traversable
This method should be implemented by classes only, i.e. not by interfaces.
hasDefiniteSize
in interface Traversable<Tuple2<K,V>>
default boolean isTraversableAgain()
Traversable
This method should be implemented by classes only, i.e. not by interfaces.
isTraversableAgain
in interface Traversable<Tuple2<K,V>>
Iterator<Tuple2<K,V>> iterator()
Traversable
Set<K> keySet()
Set
of the keys contained in this map.default int length()
Traversable
Same as Traversable.size()
.
length
in interface Traversable<Tuple2<K,V>>
default Function1<K,Option<V>> lift()
default <U> Seq<U> map(Function<? super Tuple2<K,V>,? extends U> mapper)
Map
entries to a sequence of values.
Please use map(BiFunction)
if the result has to be of type Map
.
<K2,V2> Map<K2,V2> map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Map
to form a new Map
.K2
- key's component type of the map resultV2
- value's component type of the map resultmapper
- a Function
that maps entries of type (K, V)
to entries of type (K2, V2)
Map
NullPointerException
- if mapper
is null<K2> Map<K2,V> mapKeys(Function<? super K,? extends K2> keyMapper)
Map
while preserving the corresponding values.
The size of the result map may be smaller if keyMapper
maps two or more distinct keys to the same new key.
In this case the value at the latest
of the original keys is retained.
Order of keys is predictable in TreeMap
(by comparator) and LinkedHashMap
(insertion-order) and not predictable in HashMap
.
K2
- the new key typekeyMapper
- a Function
that maps keys of type V
to keys of type V2
Map
NullPointerException
- if keyMapper
is null<K2> Map<K2,V> mapKeys(Function<? super K,? extends K2> keyMapper, BiFunction<? super V,? super V,? extends V> valueMerge)
Map
while preserving the corresponding values and applying a value merge function on collisions.
The size of the result map may be smaller if keyMapper
maps two or more distinct keys to the same new key.
In this case the associated values will be combined using valueMerge
.
K2
- the new key typekeyMapper
- a Function
that maps keys of type V
to keys of type V2
valueMerge
- a BiFunction
that merges valuesMap
NullPointerException
- if keyMapper
is null<V2> Map<K,V2> mapValues(Function<? super V,? extends V2> valueMapper)
Map
while preserving the corresponding keys.V2
- the new value typevalueMapper
- a Function
that maps values of type V
to values of type V2
Map
NullPointerException
- if valueMapper
is nullMap<K,V> merge(Map<? extends K,? extends V> that)
this
map and that
map.
If collisions occur, the value of this
map is taken.
that
- the other mapNullPointerException
- if that map is null<U extends V> Map<K,V> merge(Map<? extends K,U> that, BiFunction<? super V,? super U,? extends V> collisionResolution)
this
map and that
map.
Uses the specified collision resolution function if two keys are the same.
The collision resolution function will always take the first argument from this
map
and the second from that
map.
U
- value type of that Mapthat
- the other mapcollisionResolution
- the collision resolution functionNullPointerException
- if that map or the given collision resolution function is nullMap<K,V> put(K key, V value)
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyMap<K,V> put(Tuple2<? extends K,? extends V> entry)
put(entry._1, entry._2)
.entry
- A Tuple2 containing the key and value<U extends V> Map<K,V> put(K key, U value, BiFunction<? super V,? super U,? extends V> merge)
U
- the value typekey
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keymerge
- function taking the old and new values and merging them.<U extends V> Map<K,V> put(Tuple2<? extends K,U> entry, BiFunction<? super V,? super U,? extends V> merge)
put(entry._1, entry._2, merge)
.U
- the value typeentry
- A Tuple2 containing the key and valuemerge
- function taking the old and new values and merging them.Map<K,V> remove(K key)
key
- key whose mapping is to be removed from the mapMap<K,V> removeAll(BiPredicate<? super K,? super V> predicate)
predicate
- the predicate used to test elementsNullPointerException
- if predicate
is nullMap<K,V> removeAll(Iterable<? extends K> keys)
keys
- keys are to be removed from the mapMap<K,V> removeKeys(Predicate<? super K> predicate)
predicate
- the predicate used to test keys of elementsNullPointerException
- if predicate
is nullMap<K,V> removeValues(Predicate<? super V> predicate)
predicate
- the predicate used to test values of elementsNullPointerException
- if predicate
is nulldefault <U> Seq<U> scanLeft(U zero, BiFunction<? super U,? super Tuple2<K,V>,? extends U> operation)
Traversable
scanLeft
in interface Traversable<Tuple2<K,V>>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementdefault <U> Seq<U> scanRight(U zero, BiFunction<? super Tuple2<K,V>,? super U,? extends U> operation)
Traversable
scanRight
in interface Traversable<Tuple2<K,V>>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementint size()
Traversable
Same as Traversable.length()
.
size
in interface Traversable<Tuple2<K,V>>
default Spliterator<Tuple2<K,V>> spliterator()
spliterator
in interface Iterable<Tuple2<K,V>>
Map<K,V> toJavaMap()
Map
to a java.util.Map
while preserving characteristics
like insertion order (LinkedHashMap
) and sort order (SortedMap
).java.util.Map
instancedefault <U> U transform(Function<? super Map<K,V>,? extends U> f)
Map
.U
- Type of transformation resultf
- A transformationU
NullPointerException
- if f
is nulldefault <U> Seq<U> traverse(BiFunction<K,V,? extends U> mapper)
default <T1,T2> Tuple2<Seq<T1>,Seq<T2>> unzip(BiFunction<? super K,? super V,Tuple2<? extends T1,? extends T2>> unzipper)
default <T1,T2> Tuple2<Seq<T1>,Seq<T2>> unzip(Function<? super Tuple2<K,V>,Tuple2<? extends T1,? extends T2>> unzipper)
Traversable
unzip
in interface Traversable<Tuple2<K,V>>
T1
- 1st element type of a pair returned by unzipperT2
- 2nd element type of a pair returned by unzipperunzipper
- a function which converts elements of this to pairsdefault <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> unzip3(BiFunction<? super K,? super V,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
default <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> unzip3(Function<? super Tuple2<K,V>,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Traversable
unzip3
in interface Traversable<Tuple2<K,V>>
T1
- 1st element type of a triplet returned by unzipperT2
- 2nd element type of a triplet returned by unzipperT3
- 3rd element type of a triplet returned by unzipperunzipper
- a function which converts elements of this to pairsdefault Function1<K,V> withDefault(Function<? super K,? extends V> defaultFunction)
defaultFunction
- function to evaluate for all keys not present in the mapdefault Function1<K,V> withDefaultValue(V defaultValue)
defaultValue
- default value to return for all keys not present in the mapdefault <U> Seq<Tuple2<Tuple2<K,V>,U>> zip(Iterable<? extends U> that)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zip
in interface Traversable<Tuple2<K,V>>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.that
iterable.default <U,R> Seq<R> zipWith(Iterable<? extends U> that, BiFunction<? super Tuple2<K,V>,? super U,? extends R> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWith
in interface Traversable<Tuple2<K,V>>
U
- The type of the second parameter of the mapper.R
- The type of the mapped elements.that
- The Iterable providing the second parameter of the mapper.mapper
- a mapper.that
iterable.default <U> Seq<Tuple2<Tuple2<K,V>,U>> zipAll(Iterable<? extends U> that, Tuple2<K,V> thisElem, U thatElem)
Traversable
The length of the returned traversable is the maximum of the lengths of this traversable and that
iterable.
Special case: if this traversable is shorter than that elements, and that elements contains duplicates, the resulting traversable may be shorter than the maximum of the lengths of this and that because a traversable contains an element at most once.
If this Traversable is shorter than that, thisElem values are used to fill the result. If that is shorter than this Traversable, thatElem values are used to fill the result.
zipAll
in interface Traversable<Tuple2<K,V>>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.thisElem
- The element to be used to fill up the result if this traversable is shorter than that.thatElem
- The element to be used to fill up the result if that is shorter than this traversable.default Seq<Tuple2<Tuple2<K,V>,Integer>> zipWithIndex()
Traversable
zipWithIndex
in interface Traversable<Tuple2<K,V>>
default <U> Seq<U> zipWithIndex(BiFunction<? super Tuple2<K,V>,? super Integer,? extends U> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWithIndex
in interface Traversable<Tuple2<K,V>>
U
- The type of the mapped elements.mapper
- a mapper.that
iterable.Map<K,V> distinct()
Traversable
equals
.distinct
in interface Traversable<Tuple2<K,V>>
Traversable
containing this elements without duplicatesMap<K,V> distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Traversable
comparator
.distinctBy
in interface Traversable<Tuple2<K,V>>
comparator
- A comparatorTraversable
containing this elements without duplicates<U> Map<K,V> distinctBy(Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Traversable
equals
.
The elements of the result are determined in the order of their occurrence - first match wins.
distinctBy
in interface Traversable<Tuple2<K,V>>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatesMap<K,V> drop(int n)
Traversable
drop
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.Map<K,V> dropRight(int n)
Traversable
dropRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.Map<K,V> dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Note: This is essentially the same as dropWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
dropUntil
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.Map<K,V> dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
dropWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements starting with the first.Map<K,V> filter(Predicate<? super Tuple2<K,V>> predicate)
Traversable
filter
in interface Traversable<Tuple2<K,V>>
predicate
- A predicate<C> Map<C,? extends Map<K,V>> groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Traversable
groupBy
in interface Traversable<Tuple2<K,V>>
C
- classified class typeclassifier
- A function which classifies elements into classesIterator<? extends Map<K,V>> grouped(int size)
Traversable
Traversable
into fixed size blocks.
Let length be the length of this Iterable. Then grouped is defined as follows:
this.isEmpty()
, the resulting Iterator
is empty.size <= length
, the resulting Iterator
will contain length / size
blocks of size
size
and maybe a non-empty block of size length % size
, if there are remaining elements.size > length
, the resulting Iterator
will contain one block of size length
.
[].grouped(1) = []
[].grouped(0) throws
[].grouped(-1) throws
[1,2,3,4].grouped(2) = [[1,2],[3,4]]
[1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]]
[1,2,3,4].grouped(5) = [[1,2,3,4]]
Please note that grouped(int)
is a special case of Traversable.sliding(int, int), i.e.
grouped(size)
is the same as sliding(size, size)
.grouped
in interface Traversable<Tuple2<K,V>>
size
- a positive block sizedefault boolean isDistinct()
Traversable
isDistinct
in interface Traversable<Tuple2<K,V>>
Map<K,V> init()
Traversable
init
in interface Traversable<Tuple2<K,V>>
Option<? extends Map<K,V>> initOption()
Traversable
Option
.initOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.Tuple2<? extends Map<K,V>,? extends Map<K,V>> partition(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Traversable
by splitting this elements in two in distinct tarversables
according to a predicate.partition
in interface Traversable<Tuple2<K,V>>
predicate
- A predicate which classifies an element if it is in the first or the second traversable.Traversable
contains all elements that satisfy the given predicate
, the second Traversable
contains all elements that don't. The original order of elements is preserved.Map<K,V> peek(Consumer<? super Tuple2<K,V>> action)
Value
action
on the first element if this is an eager implementation.
Performs the given action
on all elements (the first immediately, successive deferred),
if this is a lazy implementation.Map<K,V> replace(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replace
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Map<K,V> replaceValue(K key, V value)
key
- the key of the element to be substituted.value
- the new value to be associated with the keyMap<K,V> replace(K key, V oldValue, V newValue)
key
- the key of the element to be substituted.oldValue
- the expected current value that the key is currently mapped tonewValue
- the new value to be associated with the keyMap<K,V> replaceAll(BiFunction<? super K,? super V,? extends V> function)
function
- function transforming key and current value to a new valueMap<K,V> replaceAll(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replaceAll
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Map<K,V> retainAll(Iterable<? extends Tuple2<K,V>> elements)
Traversable
retainAll
in interface Traversable<Tuple2<K,V>>
elements
- Elements to be kept.Map<K,V> scan(Tuple2<K,V> zero, BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Traversable
scan
in interface Traversable<Tuple2<K,V>>
zero
- neutral element for the operator opoperation
- the associative operator for the scanIterator<? extends Map<K,V>> sliding(int size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(int, int)
.sliding
in interface Traversable<Tuple2<K,V>>
size
- a positive window sizeIterator<? extends Map<K,V>> sliding(int size, int step)
Traversable
size
and step
size over this Traversable
.
Examples:
[].sliding(1,1) = []
[1,2,3,4,5].sliding(2,3) = [[1,2],[4,5]]
[1,2,3,4,5].sliding(2,4) = [[1,2],[5]]
[1,2,3,4,5].sliding(2,5) = [[1,2]]
[1,2,3,4].sliding(5,3) = [[1,2,3,4],[4]]
sliding
in interface Traversable<Tuple2<K,V>>
size
- a positive window sizestep
- a positive step sizeTuple2<? extends Map<K,V>,? extends Map<K,V>> span(Predicate<? super Tuple2<K,V>> predicate)
Traversable
predicate
and the second element is the remainder.span
in interface Traversable<Tuple2<K,V>>
predicate
- A predicate.Map<K,V> tail()
Traversable
tail
in interface Traversable<Tuple2<K,V>>
Option<? extends Map<K,V>> tailOption()
Traversable
Option
.tailOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.Map<K,V> take(int n)
Traversable
The result is equivalent to sublist(0, max(0, min(length(), n)))
but does not throw if n < 0
or
n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
take
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to take.Map<K,V> takeRight(int n)
Traversable
The result is equivalent to sublist(max(0, min(length(), length() - n)), n)
, i.e. takeRight will not
throw if n < 0
or n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
takeRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to take.Map<K,V> takeUntil(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Note: This is essentially the same as takeWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
takeUntil
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.Map<K,V> takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
takeWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for the contained elements.Copyright © 2016. All Rights Reserved.