scala.collection.immutable

trait MapLike

[source: scala/collection/immutable/MapLike.scala]

trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]]
extends MapLike[A, B, This]

A generic template for immutable maps from keys of type A to values of type B.
To implement a concrete map, you need to provide implementations of the following methods (where This is the type of the map in question):

    def get(key: A): Option[B]
    def iterator: Iterator[(A, B)]
    def + [B1 >: B](kv: (A, B)): Map[A, B1]
    def - (key: A): This

If you wish that methods like, take, drop, filter return the same kind of map, you should also override:

    def empty: This

It is also good idea to override methods foreach and size for efficiency.

Author
Martin Odersky
Version
2.8
Since
2.8
Direct Known Subclasses:
HashMap, IntMap, ListMap, LongMap, Map, SortedMap, TreeMap

Method Summary
override def + [B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : Map[A, B1]
Adds two or more elements to this collection and returns a new collection.
abstract def + [B1 >: B](kv : (A, B1)) : Map[A, B1]
Add a key/value pair to this map, returning a new map.
override def ++ [B1 >: B](elems : Traversable[(A, B1)]) : Map[A, B1]
Adds a number of elements provided by a traversable object and returns a new collection with the added elements.
override def ++ [B1 >: B](iter : Iterator[(A, B1)]) : Map[A, B1]
Adds a number of elements provided by an iterator and returns a new collection with the added elements.
override def filterNot (p : ((A, B)) => Boolean) : This
Returns a new map with all key/value pairs for which the predicate p returns true.
def transform [C, That](f : (A, B) => C)(implicit bf : CanBuildFrom[This, (A, C), That]) : That
This function transforms all the values of mappings contained in this map with function f.
def update [B1 >: B](key : A, value : B1) : Map[A, B1]
override def updated [B1 >: B](key : A, value : B1) : Map[A, B1]
A new immutable map containing updating this map with a given key/value mapping.
Methods inherited from MapLike
empty (abstract), get (abstract), iterator (abstract), - (abstract), newBuilder, isEmpty, getOrElse, apply, contains, isDefinedAt, keySet, keysIterator, keys, valuesIterable, valuesIterator, values, default, filterKeys, mapValues, mapElements, addString, stringPrefix, toString, hashCode, equals
Methods inherited from Subtractable
-, --, --
Methods inherited from IterableLike
thisCollection, toCollection, elements, foreach, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, view, view, first, firstOption, projection
Methods inherited from TraversableLike
repr, nonEmpty, size, hasDefiniteSize, ++, ++, map, flatMap, filter, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toSeq, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, withFilter
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
override def updated[B1 >: B](key : A, value : B1) : Map[A, B1]
A new immutable map containing updating this map with a given key/value mapping.
Parameters
key - the key
value - the value
Returns
A new map with the new key/value mapping
Overrides
MapLike.updated

abstract def +[B1 >: B](kv : (A, B1)) : Map[A, B1]
Add a key/value pair to this map, returning a new map.
Parameters
kv - the key/value pair
Returns
A new map with the new binding added to this map
Overrides
MapLike.+

override def +[B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : Map[A, B1]
Adds two or more elements to this collection and returns a new collection.
Parameters
elem1 - the first element to add.
elem2 - the second element to add.
elems - the remaining elements to add.
Overrides
MapLike.+

override def ++[B1 >: B](elems : Traversable[(A, B1)]) : Map[A, B1]
Adds a number of elements provided by a traversable object and returns a new collection with the added elements.
Parameters
elems - the traversable object.
Overrides
MapLike.++

override def ++[B1 >: B](iter : Iterator[(A, B1)]) : Map[A, B1]
Adds a number of elements provided by an iterator and returns a new collection with the added elements.
Parameters
iter - the iterator
Overrides
MapLike.++

def transform[C, That](f : (A, B) => C)(implicit bf : CanBuildFrom[This, (A, C), That]) : That
This function transforms all the values of mappings contained in this map with function f.
Parameters
f - A function over keys and values
Returns
the updated map

override def filterNot(p : ((A, B)) => Boolean) : This
Returns a new map with all key/value pairs for which the predicate p returns true.
Parameters
p - A predicate over key-value pairs
Notes
This method works by successively removing elements fro which the predicate is false from this set. If removal is slow, or you expect that most elements of the set$ will be removed, you might consider using filter with a negated predicate instead.

@deprecated("use `updated' instead")

def update[B1 >: B](key : A, value : B1) : Map[A, B1]