1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.collection
import generic._
/** A map 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 elements: Iterator[(A, B)]
* def + [B1 >: B](kv: (A, B1)): This
* 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 might also be a good idea to override methods foreach and size for efficiency.
*
* @note If you do not have speicifc implementations for `add` and `-` in mind, you
* might consider inheriting from `DefaultMap` instead.
*
* @note Of you additions and mutations return the same kind of map as the map you are defining,
* you should inherit from `MapTemplate` as well.
*/
trait Map[A, +B] extends Iterable[(A, B)] with MapTemplate[A, B, Map[A, B]] {
def empty: Map[A, B] = Map.empty
}
/* Factory object for `Map` class */
object Map extends ImmutableMapFactory[immutable.Map] {
def empty[A, B]: immutable.Map[A, B] = immutable.Map.empty
implicit def builderFactory[A, B]: BuilderFactory[(A, B), Map[A, B], Coll] = new MapBuilderFactory[A, B]
}
|