Map2

scala.collection.immutable.Map.Map2
final class Map2[K, +V](key1: K, value1: V, key2: K, value2: V) extends AbstractMap[K, V], StrictOptimizedIterableOps[(K, V), Iterable, Map[K, V]], Serializable

Attributes

Source
Map.scala
Graph
Supertypes
trait Serializable
trait StrictOptimizedIterableOps[(K, V), Iterable, Map[K, V]]
class AbstractMap[K, V]
trait Map[K, V]
trait MapOps[K, V, Map, Map[K, V]]
trait Iterable[(K, V)]
class AbstractMap[K, V]
trait Map[K, V]
trait Equals
trait MapOps[K, V, Map, Map[K, V]]
trait PartialFunction[K, V]
trait K => V
class AbstractIterable[(K, V)]
trait Iterable[(K, V)]
trait IterableOps[(K, V), Iterable, Map[K, V]]
trait IterableOnceOps[(K, V), Iterable, Map[K, V]]
trait IterableOnce[(K, V)]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def apply(key: K): V

Retrieves the value which is associated with the given key.

Retrieves the value which is associated with the given key. This method invokes the default method of the map if there is no mapping from the given key to a value. Unless overridden, the default method throws a NoSuchElementException.

Value parameters

key

the key

Attributes

Returns

the value associated with the given key, or the result of the map's default method, if none exists.

Definition Classes
Source
Map.scala
override def contains(key: K): Boolean

Tests whether this map contains a binding for a key.

Tests whether this map contains a binding for a key.

Value parameters

key

the key

Attributes

Returns

true if there is a binding for key in this map, false otherwise.

Definition Classes
Source
Map.scala
override def exists(p: ((K, V)) => Boolean): Boolean

Tests whether a predicate holds for at least one element of this immutable map.

Tests whether a predicate holds for at least one element of this immutable map.

Note: may not terminate for infinite-sized collections.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

true if the given predicate p is satisfied by at least one element of this immutable map, otherwise false

Definition Classes
Source
Map.scala
override def forall(p: ((K, V)) => Boolean): Boolean

Tests whether a predicate holds for all elements of this immutable map.

Tests whether a predicate holds for all elements of this immutable map.

Note: may not terminate for infinite-sized collections.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

true if this immutable map is empty or the given predicate p holds for all elements of this immutable map, otherwise false.

Definition Classes
Source
Map.scala
override def foreach[U](f: ((K, V)) => U): Unit

Applies f to each element for its side effects.

Applies f to each element for its side effects. Note: U parameter needed to help scalac's type inference.

Attributes

Definition Classes
Source
Map.scala
def get(key: K): Option[V]

Optionally returns the value associated with a key.

Optionally returns the value associated with a key.

Value parameters

key

the key value

Attributes

Returns

an option value containing the value associated with key in this map, or None if none exists.

Source
Map.scala
override def getOrElse[V1 >: V](key: K, default: => V1): V1

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

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

Type parameters

V1

the result type of the default computation.

Value parameters

default

a computation that yields a default value in case no binding for key is found in the map.

key

the key.

Attributes

Returns

the value associated with key if it exists, otherwise the result of the default computation.

Definition Classes
Source
Map.scala
override def hashCode(): Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Map -> Any
Source
Map.scala
override def isEmpty: Boolean

Tests whether the immutable map is empty.

Tests whether the immutable map is empty.

Note: The default implementation creates and discards an iterator.

Note: Implementations in subclasses that are not repeatedly iterable must take care not to consume any elements when isEmpty is called.

Attributes

Returns

true if the immutable map contains no elements, false otherwise.

Definition Classes
Source
Map.scala
def iterator: Iterator[(K, V)]

An scala.collection.Iterator over the elements of this immutable map.

An scala.collection.Iterator over the elements of this immutable map.

If an IterableOnce object is in fact an scala.collection.Iterator, this method always returns itself, in its current state, but if it is an scala.collection.Iterable, this method always returns a new scala.collection.Iterator.

Attributes

Source
Map.scala
override def keysIterator: Iterator[K]

An Iterator of the keys contained by this map.

An Iterator of the keys contained by this map.

Attributes

Returns

an Iterator of the keys contained by this map

Definition Classes
Source
Map.scala
override def knownSize: Int

The number of elements in this immutable map, if it can be cheaply computed, -1 otherwise.

The number of elements in this immutable map, if it can be cheaply computed, -1 otherwise. Cheaply usually means: Not requiring a collection traversal.

Attributes

Definition Classes
Source
Map.scala
def removed(key: K): Map[K, V]

Removes a key from this map, returning a new map.

Removes a key from this map, returning a new map.

Value parameters

key

the key to be removed

Attributes

Returns

a new map without a binding for key

Source
Map.scala
override def size: Int

The size of this immutable map.

The size of this immutable map.

Note: will not terminate for infinite-sized collections.

Attributes

Returns

the number of elements in this immutable map.

Definition Classes
Source
Map.scala
override def transform[W](f: (K, V) => W): Map[K, W]

This function transforms all the values of mappings contained in this map with function f.

This function transforms all the values of mappings contained in this map with function f.

Value parameters

f

A function over keys and values

Attributes

Returns

the updated map

Definition Classes
Source
Map.scala
def updated[V1 >: V](key: K, value: V1): Map[K, V1]

Creates a new map obtained by updating this map with a given key/value pair.

Creates a new map obtained by updating this map with a given key/value pair.

Type parameters

V1

the type of the added value

Value parameters

key

the key

value

the value

Attributes

Returns

A new map with the new key/value mapping added to this map.

Source
Map.scala
override def valuesIterator: Iterator[V]

Creates an iterator for all values in this map.

Creates an iterator for all values in this map.

Attributes

Returns

an iterator over all values that are associated with some key in this map.

Definition Classes
Source
Map.scala

Inherited methods

override def +[V1 >: V](kv: (K, V1)): Map[K, V1]

Alias for updated

Alias for updated

Type parameters

V1

the type of the value in the key/value pair.

Value parameters

kv

the key/value pair.

Attributes

Returns

A new map with the new binding added to this map.

Definition Classes
Inherited from:
MapOps
Source
Map.scala
final def ++[B >: (K, V)](suffix: IterableOnce[B]): Iterable[B]

Alias for concat

Alias for concat

Attributes

Inherited from:
IterableOps
Source
Iterable.scala
def ++[V2 >: V](xs: IterableOnce[(K, V2)]): Map[K, V2]

Alias for concat

Alias for concat

Attributes

Inherited from:
MapOps
Source
Map.scala
final def -(key: K): Map[K, V]

Alias for removed

Alias for removed

Attributes

Inherited from:
MapOps
Source
Map.scala
final override def --(keys: IterableOnce[K]): Map[K, V]

Alias for removedAll

Alias for removedAll

Attributes

Definition Classes
Inherited from:
MapOps
Source
Map.scala
final def addString(b: StringBuilder): b.type

Appends all elements of this collection to a string builder.

Appends all elements of this collection to a string builder. The written text consists of the string representations (w.r.t. the method toString) of all elements of this collection without any separator string.

Example:

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = new StringBuilder()
b: StringBuilder =

scala> val h = a.addString(b)
h: StringBuilder = 1234

Value parameters

b

the string builder to which elements are appended.

Attributes

Returns

the string builder b to which elements were appended.

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
final def addString(b: StringBuilder, sep: String): b.type

Appends all elements of this collection to a string builder using a separator string.

Appends all elements of this collection to a string builder using a separator string. The written text consists of the string representations (w.r.t. the method toString) of all elements of this collection, separated by the string sep.

Example:

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = new StringBuilder()
b: StringBuilder =

scala> a.addString(b, ", ")
res0: StringBuilder = 1, 2, 3, 4

Value parameters

b

the string builder to which elements are appended.

sep

the separator string.

Attributes

Returns

the string builder b to which elements were appended.

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
override def addString(sb: StringBuilder, start: String, sep: String, end: String): sb.type

Appends all elements of this map to a string builder using start, end, and separator strings.

Appends all elements of this map to a string builder using start, end, and separator strings. The written text begins with the string start and ends with the string end. Inside, the string representations (w.r.t. the method toString) of all elements of this map are separated by the string sep.

Example:

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = new StringBuilder()
b: StringBuilder =

scala> a.addString(b , "List(" , ", " , ")")
res5: StringBuilder = List(1, 2, 3, 4)

Value parameters

b

the string builder to which elements are appended.

end

the ending string.

sep

the separator string.

start

the starting string.

Attributes

Returns

the string builder b to which elements were appended.

Definition Classes
Inherited from:
MapOps
Source
Map.scala
def andThen[C](k: PartialFunction[V, C]): PartialFunction[K, C]

Composes this partial function with another partial function that gets applied to results of this partial function.

Composes this partial function with another partial function that gets applied to results of this partial function.

Note that calling isDefinedAt on the resulting partial function may apply the first partial function and execute its side effect. For efficiency, it is recommended to call applyOrElse instead of isDefinedAt or apply.

Type parameters

C

the result type of the transformation function.

Value parameters

k

the transformation function

Attributes

Returns

a partial function with the domain of this partial function narrowed by other partial function, which maps arguments x to k(this(x)).

Inherited from:
PartialFunction
Source
PartialFunction.scala
override def andThen[C](k: V => C): PartialFunction[K, C]

Composes this partial function with a transformation function that gets applied to results of this partial function.

Composes this partial function with a transformation function that gets applied to results of this partial function.

If the runtime type of the function is a PartialFunction then the other andThen method is used (note its cautions).

Type parameters

C

the result type of the transformation function.

Value parameters

k

the transformation function

Attributes

Returns

a partial function with the domain of this partial function, possibly narrowed by the specified function, which maps arguments x to k(this(x)).

Definition Classes
Inherited from:
PartialFunction
Source
PartialFunction.scala
override def applyOrElse[K1 <: K, V1 >: V](x: K1, default: K1 => V1): V1

Applies this partial function to the given argument when it is contained in the function domain.

Applies this partial function to the given argument when it is contained in the function domain. Applies fallback function where this partial function is not defined.

Note that expression pf.applyOrElse(x, default) is equivalent to

if(pf isDefinedAt x) pf(x) else default(x)

except that applyOrElse method can be implemented more efficiently. For all partial function literals the compiler generates an applyOrElse implementation which avoids double evaluation of pattern matchers and guards. This makes applyOrElse the basis for the efficient implementation for many operations and scenarios, such as:

- combining partial functions into orElse/andThen chains does not lead to excessive apply/isDefinedAt evaluation - lift and unlift do not evaluate source functions twice on each invocation - runWith allows efficient imperative-style combining of partial functions with conditionally applied actions

For non-literal partial function classes with nontrivial isDefinedAt method it is recommended to override applyOrElse with custom implementation that avoids double isDefinedAt evaluation. This may result in better performance and more predictable behavior w.r.t. side effects.

Value parameters

default

the fallback function

x

the function argument

Attributes

Returns

the result of this function or fallback function application.

Definition Classes
Inherited from:
MapOps
Source
Map.scala
def canEqual(that: Any): Boolean

Checks whether this instance can possibly equal that.

Checks whether this instance can possibly equal that.

A method that should be called from every well-designed equals method that is open to be overridden in a subclass. See Programming in Scala, Chapter 28 for discussion and design.

Value parameters

that

the value being probed for possible equality

Attributes

Returns

true if this instance can possibly equal that, otherwise false

Inherited from:
Map
Source
Map.scala
override def collect[B](pf: PartialFunction[(K, V), B]): Iterable[B]

Builds a new iterable collection by applying a partial function to all elements of this iterable collection on which the function is defined.

Builds a new iterable collection by applying a partial function to all elements of this iterable collection on which the function is defined.

Type parameters

B

the element type of the returned iterable collection.

Value parameters

pf

the partial function which filters and maps the iterable collection.

Attributes

Returns

a new iterable collection resulting from applying the given partial function pf to each element on which it is defined and collecting the results. The order of the elements is preserved.

Definition Classes
Inherited from:
StrictOptimizedIterableOps
Source
StrictOptimizedIterableOps.scala
def collect[K2, V2](pf: PartialFunction[(K, V), (K2, V2)]): Map[K2, V2]

Builds a new collection by applying a partial function to all elements of this map on which the function is defined.

Builds a new collection by applying a partial function to all elements of this map on which the function is defined.

Type parameters

K2

the key type of the returned map.

V2

the value type of the returned map.

Value parameters

pf

the partial function which filters and maps the map.

Attributes

Returns

a new map resulting from applying the given partial function pf to each element on which it is defined and collecting the results. The order of the elements is preserved.

Inherited from:
MapOps
Source
Map.scala
def collectFirst[B](pf: PartialFunction[(K, V), B]): Option[B]

Finds the first element of the collection for which the given partial function is defined, and applies the partial function to it.

Finds the first element of the collection for which the given partial function is defined, and applies the partial function to it.

Note: may not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered.

Value parameters

pf

the partial function

Attributes

Returns

an option value containing pf applied to the first value for which it is defined, or None if none exists.

Example

Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
def compose[R](k: PartialFunction[R, K]): PartialFunction[R, V]

Composes another partial function k with this partial function so that this partial function gets applied to results of k.

Composes another partial function k with this partial function so that this partial function gets applied to results of k.

Note that calling isDefinedAt on the resulting partial function may apply the first partial function and execute its side effect. For efficiency, it is recommended to call applyOrElse instead of isDefinedAt or apply.

Type parameters

R

the parameter type of the transformation function.

Value parameters

k

the transformation function

Attributes

Returns

a partial function with the domain of other partial function narrowed by this partial function, which maps arguments x to this(k(x)).

Inherited from:
PartialFunction
Source
PartialFunction.scala
def compose[A](g: A => K): A => V

Composes two instances of Function1 in a new Function1, with this function applied last.

Composes two instances of Function1 in a new Function1, with this function applied last.

Type parameters

A

the type to which function g can be applied

Value parameters

g

a function A => T1

Attributes

Returns

a new function f such that f(x) == apply(g(x))

Inherited from:
Function1
Source
Function1.scala
def concat[B >: (K, V)](suffix: IterableOnce[B]): Iterable[B]

Returns a new iterable collection containing the elements from the left hand operand followed by the elements from the right hand operand.

Returns a new iterable collection containing the elements from the left hand operand followed by the elements from the right hand operand. The element type of the iterable collection is the most specific superclass encompassing the element types of the two operands.

Type parameters

B

the element type of the returned collection.

Value parameters

suffix

the iterable to append.

Attributes

Returns

a new iterable collection which contains all elements of this iterable collection followed by all elements of suffix.

Inherited from:
IterableOps
Source
Iterable.scala
def concat[V2 >: V](suffix: IterableOnce[(K, V2)]): Map[K, V2]

Returns a new map containing the elements from the left hand operand followed by the elements from the right hand operand.

Returns a new map containing the elements from the left hand operand followed by the elements from the right hand operand. The element type of the map is the most specific superclass encompassing the element types of the two operands.

Value parameters

suffix

the iterable to append.

Attributes

Returns

a new map which contains all elements of this map followed by all elements of suffix.

Inherited from:
MapOps
Source
Map.scala
def copyToArray[B >: (K, V)](xs: Array[B], start: Int, len: Int): Int

Copy elements to an array, returning the number of elements written.

Copy elements to an array, returning the number of elements written.

Fills the given array xs starting at index start with at most len elements of this collection.

Copying will stop once either all the elements of this collection have been copied, or the end of the array is reached, or len elements have been copied.

Type parameters

B

the type of the elements of the array.

Value parameters

len

the maximal number of elements to copy.

start

the starting index of xs.

xs

the array to fill.

Attributes

Returns

the number of elements written to the array

Note

Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
def copyToArray[B >: (K, V)](xs: Array[B], start: Int): Int

Copies elements to an array, returning the number of elements written.

Copies elements to an array, returning the number of elements written.

Fills the given array xs starting at index start with values of this collection.

Copying will stop once either all the elements of this collection have been copied, or the end of the array is reached.

Type parameters

B

the type of the elements of the array.

Value parameters

start

the starting index of xs.

xs

the array to fill.

Attributes

Returns

the number of elements written to the array

Note

Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
def copyToArray[B >: (K, V)](xs: Array[B]): Int

Copies elements to an array, returning the number of elements written.

Copies elements to an array, returning the number of elements written.

Fills the given array xs starting at index start with values of this collection.

Copying will stop once either all the elements of this collection have been copied, or the end of the array is reached.

Type parameters

B

the type of the elements of the array.

Value parameters

xs

the array to fill.

Attributes

Returns

the number of elements written to the array

Note

Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
def corresponds[B](that: IterableOnce[B])(p: ((K, V), B) => Boolean): Boolean

Tests whether every element of this collection's iterator relates to the corresponding element of another collection by satisfying a test predicate.

Tests whether every element of this collection's iterator relates to the corresponding element of another collection by satisfying a test predicate.

Note: will not terminate for infinite-sized collections.

Type parameters

B

the type of the elements of that

Value parameters

p

the test predicate, which relates elements from both collections

that

the other collection

Attributes

Returns

true if both collections have the same length and p(x, y) is true for all corresponding elements x of this iterator and y of that, otherwise false

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
def count(p: ((K, V)) => Boolean): Int

Counts the number of elements in the collection which satisfy a predicate.

Counts the number of elements in the collection which satisfy a predicate.

Note: will not terminate for infinite-sized collections.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

the number of elements satisfying the predicate p.

Inherited from:
IterableOnceOps
Source
IterableOnce.scala
def