Top Description Inners Fields Methods
io.vavr.collection

public Interface Multimap<K, V>

extends Traversable<Tuple2<K, V>>, PartialFunction<K, Traversable<V>>, Serializable
Known Direct Subinterfaces
io.vavr.collection.SortedMultimap
Known Direct Implementers
io.vavr.collection.AbstractMultimap
Type Parameters
<K>
Key type
<V>
Value type
Imports
io.vavr.*, io.vavr.control.Option, java.io.Serializable, java.util.*, java.util.function.*

An immutable Multimap interface.

Basic operations:

Conversion: Filtering: Iteration: Transformation:
Author
Ruslan Sennov

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
public static final long

Method Summary

Modifier and TypeMethod and Description
public default Traversable<V>
apply(K
the argument
key
)

Implements io.vavr.PartialFunction.apply.

Deprecated

Applies this function to the given argument and returns the result.

public Map<K, Traversable<V>>

Returns:

Map<K, Traversable<V>>
asMap
()

Converts this Multimap to a Map

public default PartialFunction<K, Traversable<V>>

Returns:

a new PartialFunction
asPartialFunction
()

Turns this Multimap into a PartialFunction which is defined at a specific index, if this Multimap contains the given key.

public <
key's component type of the multimap result
K2
,
value's component type of the multimap result
V2
>
Multimap<K2, V2>

Returns:

a new Multimap
bimap
(Function<? super K, ? extends K2>
a Function that maps the keys of type K to keys of type K2
keyMapper
,
Function<? super V, ? extends V2>
a Function that the values of type V to values of type V2
valueMapper
)

Maps this Multimap to a new Multimap with different component type by applying a function to its elements.

public default <R> Seq<R>
collect(PartialFunction<? super Tuple2<K, V>, ? extends R>
A function that is not necessarily defined of all elements of this traversable.
partialFunction
)

Implements io.vavr.collection.Traversable.collect.

Collects all elements that are in the domain of the given partialFunction by mapping the elements to type R.

public default boolean
contains(Tuple2<K, V>
An Object of type A, may be null.
element
)

Overrides default io.vavr.Value.contains.

Shortcut for exists(e -> Objects.equals(e, element)), tests if the given element is contained.

public boolean

Returns:

true if this multimap contains a mapping for the specified key
containsKey
(K
key whose presence in this multimap is to be tested
key
)

Returns true if this multimap contains a mapping for the specified key.

public default boolean

Returns:

true if this multimap maps one or more keys to the specified value
containsValue
(V
value whose presence in this multimap is to be tested
value
)

Returns true if this multimap maps one or more keys to the specified value.

public Multimap<K, V>
distinct()

Redeclares io.vavr.collection.Traversable.distinct.

Returns a new version of this which contains no duplicates.

public Multimap<K, V>
distinctBy(Comparator<? super Tuple2<K, V>>
A comparator
comparator
)

Redeclares io.vavr.collection.Traversable.distinctBy.

Returns a new version of this which contains no duplicates.

public <U> Multimap<K, V>
distinctBy(Function<? super Tuple2<K, V>, ? extends U>
A key extractor
keyExtractor
)

Redeclares io.vavr.collection.Traversable.distinctBy.

Returns a new version of this which contains no duplicates.

public Multimap<K, V>
drop(int
The number of elements to drop.
n
)

Redeclares io.vavr.collection.Traversable.drop.

Drops the first n elements of this or all elements, if this length < n.

public Multimap<K, V>
dropRight(int
The number of elements to drop.
n
)

Redeclares io.vavr.collection.Traversable.dropRight.

Drops the last n elements of this or all elements, if this length < n.

public Multimap<K, V>
dropUntil(Predicate<? super Tuple2<K, V>>
A condition tested subsequently for this elements.
predicate
)

Redeclares io.vavr.collection.Traversable.dropUntil.

Drops elements until the predicate holds for the current element.

public Multimap<K, V>
dropWhile(Predicate<? super Tuple2<K, V>>
A condition tested subsequently for this elements.
predicate
)

Redeclares io.vavr.collection.Traversable.dropWhile.

Drops elements while the predicate holds for the current element.

public Multimap<K, V>

Returns:

a new Multimap
filter
(BiPredicate<? super K, ? super V>
the predicate used to test elements
predicate
)

Returns a new Multimap consisting of all elements which satisfy the given predicate.

public Multimap<K, V>
filter(Predicate<? super Tuple2<K, V>>
A predicate
predicate
)

Redeclares io.vavr.collection.Traversable.filter.

Returns a new traversable consisting of all elements which satisfy the given predicate.

public Multimap<K, V>

Returns:

a new Multimap
filterKeys
(Predicate<? super K>
the predicate used to test keys of elements
predicate
)

Returns a new Multimap consisting of all elements with keys which satisfy the given predicate.

public Multimap<K, V>

Returns:

a new Multimap
filterValues
(Predicate<? super V>
the predicate used to test values of elements
predicate
)

Returns a new Multimap consisting of all elements with values which satisfy the given predicate.

public <
key's component type of the mapped Multimap
K2
,
value's component type of the mapped Multimap
V2
>
Multimap<K2, V2>

Returns:

A new Multimap.
flatMap
(BiFunction<? super K, ? super V, ? extends Iterable<Tuple2<K2, V2>>>
A mapper
mapper
)

FlatMaps this Multimap to a new Multimap with different component type.

public default <
Component type
U
>
Seq<U>

Returns:

A sequence of flat-mapped values.
flatMap
(Function<? super Tuple2<K, V>, ? extends Iterable<? extends U>>
A mapper
mapper
)

Implements io.vavr.collection.Traversable.flatMap.

Flat-maps this entries to a sequence of values.

public default <U> U
foldRight(U
A zero element to start with.
zero
,
BiFunction<? super Tuple2<K, V>, ? super U, ? extends U>
A function which combines elements.
f
)

Implements io.vavr.collection.Traversable.foldRight.

Folds this elements from the right, starting with zero and successively calling combine.

public default void
forEach(BiConsumer<K, V>
A BiConsumer
action
)

Performs an action on key, value pair.

public Option<Traversable<V>>

Returns:

the Some of value to which the specified key is mapped, or None if this multimap contains no mapping for the key
get
(K
the key whose associated value is to be returned
key
)

Returns the Some of value to which the specified key is mapped, or None if this multimap contains no mapping for the key.

public Multimap.ContainerType

Returns:

an enum value representing the container type
getContainerType
()

Returns the type of the Traversable value container of this MultiMap.

public Traversable<V>

Returns:

the value associated with key if it exists, otherwise the result of the default value
getOrElse
(K
the key
key
,
Traversable<? extends V>
a default value
defaultValue
)

Returns the value associated with a key, or a default value if the key is not contained in the map

public <C> Map<C, ? extends Multimap<K, V>>
groupBy(Function<? super Tuple2<K, V>, ? extends C>
A function which classifies elements into classes
classifier
)

Redeclares io.vavr.collection.Traversable.groupBy.

Groups this elements by classifying the elements.

public Iterator<? extends Multimap<K, V>>
grouped(int
a positive block size
size
)

Redeclares io.vavr.collection.Traversable.grouped.

Groups this Traversable into fixed size blocks.

public default boolean
hasDefiniteSize()

Implements io.vavr.collection.Traversable.hasDefiniteSize.

Checks if this Traversable is known to have a finite size.

public Multimap<K, V>
init()

Redeclares io.vavr.collection.Traversable.init.

Dual of tail(), returning all elements except the last.

public Option<? extends Multimap<K, V>>
initOption()

Redeclares as abstract: io.vavr.collection.Traversable.initOption.

Dual of tailOption(), returning all elements except the last as Option.

public default boolean
isDefinedAt(K
a potential function argument
key
)

Implements io.vavr.PartialFunction.isDefinedAt.

Deprecated

Tests if a value is contained in the function's domain.

public default boolean
isDistinct()

Overrides default io.vavr.collection.Traversable.isDistinct.

Checks if this Traversable may consist of distinct elements only.

public default boolean
isTraversableAgain()

Implements io.vavr.collection.Traversable.isTraversableAgain.

Checks if this Traversable can be repeatedly traversed.

public Iterator<Tuple2<K, V>>
iterator()

Redeclares as abstract: io.vavr.collection.Traversable.iterator.

An iterator by means of head() and tail().

public default <
The type of the resulting elements
U
>
Iterator<U>

Returns:

An iterator through the mapped elements.
iterator
(BiFunction<K, V, ? extends U>
A function that maps (key, value) pairs to elements of type U
mapper
)

Iterates this Multimap sequentially, mapping the (key, value) pairs to elements.

public Set<K>

Returns:

Set of the keys contained in this multimap.
keySet
()

Returns the keys contained in this multimap.

public default int
length()

Implements io.vavr.collection.Traversable.length.

Computes the number of elements of this Traversable.

public <
key's component type of the multimap result
K2
,
value's component type of the multimap result
V2
>
Multimap<K2, V2>

Returns:

a new Multimap
map
(BiFunction<? super K, ? super V, Tuple2<K2, V2>>
a Function that maps entries of type (K, V) to entries of type (K2, V2)
mapper
)

Maps the entries of this Multimap to form a new Multimap.

public default <
Component type
U
>
Seq<U>

Returns:

A sequence of mapped values.
map
(Function<? super Tuple2<K, V>, ? extends U>
A mapper
mapper
)

Implements io.vavr.collection.Traversable.map.

Maps the Multimap entries to a sequence of values.

public <
the new value type
V2
>
Multimap<K, V2>

Returns:

a new Multimap
mapValues
(Function<? super V, ? extends V2>
a Function that maps values of type V to values of type V2
valueMapper
)

Maps the values of this Multimap while preserving the corresponding keys.

public Multimap<K, V>

Returns:

A merged multimap
merge
(Multimap<? extends K, ? extends V>
the other multimap
that
)

Creates a new multimap which by merging the entries of this multimap and that multimap.

public <
key type of that Multimap
K2 extends K
,
value type of that Multimap
V2 extends V
>
Multimap<K, V>

Returns:

A merged multimap
merge
(Multimap<K2, V2>
the other multimap
that
,
BiFunction<Traversable<V>, Traversable<V2>, Traversable<V>>
the collision resolution function
collisionResolution
)

Creates a new multimap which by merging the entries of this multimap and that multimap.

public static <
Key type
K
,
Value type
V
>
Multimap<K, V>

Returns:

the given multimap instance as narrowed type Multimap<K, V>.
narrow
(Multimap<? extends K, ? extends V>
A Multimap.
map
)

Narrows a widened Multimap<?

public Multimap<K, V>
orElse(Iterable<? extends Tuple2<K, V>>
An alternative Traversable
other
)

Redeclares io.vavr.collection.Traversable.orElse.

Returns this Traversable if it is nonempty, otherwise return the alternative.

public Multimap<K, V>
orElse(Supplier<? extends Iterable<? extends Tuple2<K, V>>>
An alternative Traversable supplier
supplier
)

Redeclares io.vavr.collection.Traversable.orElse.

Returns this Traversable if it is nonempty, otherwise return the result of evaluating supplier.

public Tuple2<? extends Multimap<K, V>, ? extends Multimap<K, V>>
partition(Predicate<? super Tuple2<K, V>>
A predicate which classifies an element if it is in the first or the second traversable.
predicate
)

Redeclares io.vavr.collection.Traversable.partition.

Creates a partition of this Traversable by splitting this elements in two in distinct traversables according to a predicate.

public Multimap<K, V>
peek(Consumer<? super Tuple2<K, V>>
The action that will be performed on the element(s).
action
)

Redeclares io.vavr.collection.Traversable.peek.

Performs the given action on the first element if this is an eager implementation.

public Multimap<K, V>

Returns:

A new Multimap containing these elements and that entry.
put
(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Associates the specified value with the specified key in this multimap.

public Multimap<K, V>

Returns:

A new Multimap containing these elements and that entry.
put
(Tuple2<? extends K, ? extends V>
A Tuple2 containing the key and value
entry
)

Convenience method for put(entry._1, entry._2).

public Multimap<K, V>

Returns:

a new Multimap
reject
(BiPredicate<? super K, ? super V>
the predicate used to test elements
predicate
)

Returns a new Multimap consisting of all elements which do not satisfy the given predicate.

public Multimap<K, V>
reject(Predicate<? super Tuple2<K, V>>
A predicate
predicate
)

Redeclares as abstract: io.vavr.collection.Traversable.reject.

Returns a new traversable consisting of all elements which do not satisfy the given predicate.

public Multimap<K, V>

Returns:

a new Multimap
rejectKeys
(Predicate<? super K>
the predicate used to test keys of elements
predicate
)

Returns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.

public Multimap<K, V>

Returns:

a new Multimap
rejectValues
(Predicate<? super V>
the predicate used to test values of elements
predicate
)

Returns a new Multimap consisting of all elements with values which do not satisfy the given predicate.

public Multimap<K, V>

Returns:

A new Multimap containing these elements without the entry specified by that key.
remove
(K
key whose mapping is to be removed from the multimap
key
)

Removes the mapping for a key from this multimap if it is present.

public Multimap<K, V>

Returns:

A new Multimap containing these elements without the entry specified by that key and value.
remove
(K
key whose mapping is to be removed from the multimap
key
,
V
value whose mapping is to be removed from the multimap
value
)

Removes the key-value pair from this multimap if it is present.

public Multimap<K, V>

Returns:

a new Multimap
removeAll
(BiPredicate<? super K, ? super V>
the predicate used to test elements
predicate
)
Deprecated Please use reject(BiPredicate)

Returns a new Multimap consisting of all elements which do not satisfy the given predicate.

public Multimap<K, V>

Returns:

A new Multimap containing these elements without the entries specified by that keys.
removeAll
(Iterable<? extends K>
keys are to be removed from the multimap
keys
)

Removes the mapping for a key from this multimap if it is present.

public Multimap<K, V>

Returns:

a new Multimap
removeKeys
(Predicate<? super K>
the predicate used to test keys of elements
predicate
)
Deprecated Please use rejectKeys(Predicate)

Returns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.

public Multimap<K, V>

Returns:

a new Multimap
removeValues
(Predicate<? super V>
the predicate used to test values of elements
predicate
)
Deprecated Please use rejectValues(Predicate)

Returns a new Multimap consisting of all elements with values which do not satisfy the given predicate.

public Multimap<K, V>
replace(Tuple2<K, V>
An element to be substituted.
currentElement
,
Tuple2<K, V>
A replacement for currentElement.
newElement
)

Redeclares io.vavr.collection.Traversable.replace.

Replaces the first occurrence (if exists) of the given currentElement with newElement.

public Multimap<K, V>

Returns:

a new map containing key mapped to newValue if key was contained before and oldValue was associated with the key. The old map otherwise.
replace
(K
the key of the element to be substituted
key
,
V
the expected current value associated with the key
oldValue
,
V
the new value to be associated with the key
newValue
)

Replaces the entry with the specified key and oldValue.

public Multimap<K, V>
replaceAll(Tuple2<K, V>
An element to be substituted.
currentElement
,
Tuple2<K, V>
A replacement for currentElement.
newElement
)

Redeclares io.vavr.collection.Traversable.replaceAll.

Replaces all occurrences of the given currentElement with newElement.

public Multimap<K, V>

Returns:

a new map with the same keySet but transformed values
replaceAll
(BiFunction<? super K, ? super V, ? extends V>
function transforming key and current value to a new value
function
)

Replaces each entry's values with the result of invoking the given function on that each tuple until all entries have been processed or the function throws an exception.

public Multimap<K, V>

Returns:

a new map containing key mapped to value if key was contained before. The old map otherwise
replaceValue
(K
the key of the element to be substituted
key
,
V
the new value to be associated with the key
value
)

Replaces the entry for the specified key only if it is currently mapped to some value.

public Multimap<K, V>
retainAll(Iterable<? extends Tuple2<K, V>>
Elements to be kept.
elements
)

Redeclares io.vavr.collection.Traversable.retainAll.

Keeps all occurrences of the given elements from this.

public Multimap<K, V>
scan(Tuple2<K, V>
neutral element for the operator op
zero
,
BiFunction<? super Tuple2<K, V>, ? super Tuple2<K, V>, ? extends Tuple2<K, V>>
the associative operator for the scan
operation
)

Redeclares io.vavr.collection.Traversable.scan.

Computes a prefix scan of the elements of the collection.

public default <U> Seq<U>
scanLeft(U
the initial value
zero
,
BiFunction<? super U, ? super Tuple2<K, V>, ? extends U>
the binary operator applied to the intermediate result and the element
operation
)

Implements io.vavr.collection.Traversable.scanLeft.

Produces a collection containing cumulative results of applying the operator going left to right.

public default <U> Seq<U>
scanRight(U
the initial value
zero
,
BiFunction<? super Tuple2<K, V>, ? super U, ? extends U>
the binary operator applied to the intermediate result and the element
operation
)

Implements io.vavr.collection.Traversable.scanRight.

Produces a collection containing cumulative results of applying the operator going right to left.

public int
size()

Redeclares as abstract: io.vavr.collection.Traversable.size.

Computes the number of elements of this Traversable.

public Iterator<? extends Multimap<K, V>>
slideBy(Function<? super Tuple2<K, V>, ?>
A function which classifies elements into classes
classifier
)

Redeclares io.vavr.collection.Traversable.slideBy.

Slides a non-overlapping window of a variable size over this Traversable.

public Iterator<? extends Multimap<K, V>>
sliding(int
a positive window size
size
)

Redeclares io.vavr.collection.Traversable.sliding.

Slides a window of a specific size and step size 1 over this Traversable by calling sliding(int, int).

public Iterator<? extends Multimap<K, V>>
sliding(int
a positive window size
size
,
int
a positive step size
step
)

Redeclares io.vavr.collection.Traversable.sliding.

Slides a window of a specific size and step size over this Traversable.

public Tuple2<? extends Multimap<K, V>, ? extends Multimap<K, V>>
span(Predicate<? super Tuple2<K, V>>
A predicate.
predicate
)

Redeclares io.vavr.collection.Traversable.span.

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.

public Multimap<K, V>
tail()

Redeclares io.vavr.collection.Traversable.tail.

Drops the first element of a non-empty Traversable.

public Option<? extends Multimap<K, V>>
tailOption()

Redeclares io.vavr.collection.Traversable.tailOption.

Drops the first element of a non-empty Traversable and returns an Option.

public Multimap<K, V>
take(int
The number of elements to take.
n
)

Redeclares io.vavr.collection.Traversable.take.

Takes the first n elements of this or all elements, if this length < n.

public Multimap<K, V>
takeRight(int
The number of elements to take.
n
)

Redeclares io.vavr.collection.Traversable.takeRight.

Takes the last n elements of this or all elements, if this length < n.

public Multimap<K, V>
takeUntil(Predicate<? super Tuple2<K, V>>
A condition tested subsequently for this elements.
predicate
)

Redeclares io.vavr.collection.Traversable.takeUntil.

Takes elements until the predicate holds for the current element.

public Multimap<K, V>
takeWhile(Predicate<? super Tuple2<K, V>>
A condition tested subsequently for the contained elements.
predicate
)

Redeclares io.vavr.collection.Traversable.takeWhile.

Takes elements while the predicate holds for the current element.

public Map<K, Collection<V>>

Returns:

a new java.util.Map instance
toJavaMap
()

Converts this Vavr Map to a java.util.Map while preserving characteristics like insertion order (LinkedHashMultimap) and sort order (SortedMultimap).

public default <
Type of transformation result
U
>
U

Returns:

An instance of type U
transform
(Function<? super Multimap<K, V>, ? extends U>
A transformation
f
)

Transforms this Multimap.

public default <T1, T2> Tuple2<Seq<T1>, Seq<T2>>
unzip(BiFunction<? super K, ? super V, Tuple2<? extends T1, ? extends T2>> unzipper)

public default <T1, T2> Tuple2<Seq<T1>, Seq<T2>>
unzip(Function<? super Tuple2<K, V>, Tuple2<? extends T1, ? extends T2>>
a function which converts elements of this to pairs
unzipper
)

Implements io.vavr.collection.Traversable.unzip.

Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct sets.

public 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)

public default <T1, T2, T3> Tuple3<Seq<T1>, Seq<T2>, Seq<T3>>
unzip3(Function<? super Tuple2<K, V>, Tuple3<? extends T1, ? extends T2, ? extends T3>>
a function which converts elements of this to pairs
unzipper
)

Implements io.vavr.collection.Traversable.unzip3.

Unzips this elements by mapping this elements to triples which are subsequently split into three distinct sets.

public Traversable<V>
public default <U> Seq<Tuple2<Tuple2<K, V>, U>>
zip(Iterable<? extends U>
The Iterable providing the second half of each result pair.
that
)

Implements io.vavr.collection.Traversable.zip.

Returns a traversable formed from this traversable and another Iterable collection by combining corresponding elements in pairs.

public default <U> Seq<Tuple2<Tuple2<K, V>, U>>
zipAll(Iterable<? extends U>
The Iterable providing the second half of each result pair.
that
,
Tuple2<K, V>
The element to be used to fill up the result if this traversable is shorter than that.
thisElem
,
U
The element to be used to fill up the result if that is shorter than this traversable.
thatElem
)

Implements io.vavr.collection.Traversable.zipAll.

Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in pairs.

public default <U, R> Seq<R>
zipWith(Iterable<? extends U>
The Iterable providing the second parameter of the mapper.
that
,
BiFunction<? super Tuple2<K, V>, ? super U, ? extends R>
a mapper.
mapper
)

Implements io.vavr.collection.Traversable.zipWith.

Returns a traversable formed from this traversable and another Iterable collection by mapping elements.

public default Seq<Tuple2<Tuple2<K, V>, Integer>>
zipWithIndex()

Implements io.vavr.collection.Traversable.zipWithIndex.

Zips this traversable with its indices.

public default <U> Seq<U>
zipWithIndex(BiFunction<? super Tuple2<K, V>, ? super Integer, ? extends U>
a mapper.
mapper
)

Implements io.vavr.collection.Traversable.zipWithIndex.

Zips this traversable with its indices by applying mapper provided.

Inherited from io.vavr.collection.Traversable:
arrangeByaveragecontainsAllcountequalsexistsUniquefindfindLastfoldLeftforEachWithIndexgethashCodeheadheadOptionisEmptyisOrderedisSequentialisSingleValuedlastlastOptionmaxmaxBymaxByminminByminBymkCharSeqmkCharSeqmkCharSeqmkStringmkStringmkStringnarrownonEmptyproductreduceLeftreduceLeftOptionreduceRightreduceRightOptionsinglesingleOptionspliteratorsum
Inherited from io.vavr.PartialFunction:
getIfDefinedliftunlift