scala.collection.immutable

trait MapProxy

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

trait MapProxy[A, +B]
extends Map[A, B] with MapProxyTemplate[A, B, Map[A, B]]

This is a simple wrapper class for scala.collection.mutable.Map.

It is most useful for assembling customized map abstractions dynamically using object composition and forwarding.

Author
Matthias Zenger, Martin Odersky
Version
2.0, 31/12/2006
Method Summary
override def + [B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : MapProxy[A, B1]
Adds two or more elements to this collection and returns a new collection.
override def + [B1 >: B](kv : (A, B1)) : Map[A, B1]
Add a key/value pair to this map, returning a new map.
override def - (key : A) : MapProxy[A, B]
Removes a key from this map, returning a new map
override def empty : MapProxy[A, B]
override def thisCollection : MapProxy[A, B]
override def updated [B1 >: B](key : A, value : B1) : MapProxy[A, B1]
Add a key/value pair to this map.
Methods inherited from MapProxyTemplate
get, iterator, isEmpty, getOrElse, apply, contains, isDefinedAt, keySet, keysIterator, keys, valueIterable, valuesIterator, values, default, filterKeys, mapValues, addString
Methods inherited from IterableProxyTemplate
foreach, foldRight, reduceRight, toIterable, head, takeRight, dropRight, sameElements, toStream, view, view
Methods inherited from TraversableProxyTemplate
self (abstract), nonEmpty, size, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, remove, partition, groupBy, forall, exists, count, find, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, headOption, tail, last, lastOption, init, take, drop, slice, takeWhile, dropWhile, span, splitAt, copyToBuffer, copyToArray, copyToArray, toArray, toList, toSequence, toSet, mkString, mkString, mkString, addString, addString, stringPrefix
Methods inherited from Proxy
hashCode, equals, toString
Methods inherited from Map
withDefault, withDefaultValue
Methods inherited from ImmutableMapTemplate
++, ++, transform, update
Methods inherited from MapTemplate
newBuilder, mapElements
Methods inherited from Subtractable
-, --, --
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from Iterable
companion
Methods inherited from IterableTemplate
elements, first, firstOption, toSeq, projection
Methods inherited from TraversableClass
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableTemplate
filterMap
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 thisCollection : MapProxy[A, B]

The proper way to do this would be to make self of type This. But unfortunately this makes this to be of type Traversable[A]. Since Traversable is a subtype of TraversableTemplate, all methods of this are taken from Traversable. In particular the newBuilder method is taken from Traversable, which means it yields a Traversable[A] instead of a This.

The right way out of this is to change Scala's member selection rules, so that always the most specific type will be selected, no matter whether a member is abstract or concrete. I tried to fake this by having a method thisTemplate which returns this at the Template type. But unfortunately that does not work, because we need to call newBuilder on this at the Template type (so that we get back a This) and newBuilder has to be a protected[this] because of variance.
The less appealing alternative is implemented now: Forget the self type and introduce a thisCollection which is this seen as an instance of This. We should go back to this once we have ameliorated Scala's member selection rules.


override def empty : MapProxy[A, B]
Overrides
Map.empty

override def updated[B1 >: B](key : A, value : B1) : MapProxy[A, B1]
Add a key/value pair to this map.
Parameters
key - the key
value - the value
Returns
A new map with the new binding added to this map
Overrides
Map.updated

override 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
Map.+

override def +[B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : MapProxy[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.

override def -(key : A) : MapProxy[A, B]
Removes a key from this map, returning a new map
Parameters
key - the key to be removed
Returns
A new map without a binding for key