summaryrefslogblamecommitdiff
path: root/src/library/scala/collection/Map.scala
blob: 72afa218c21cb976af4a62b75a43e447e9e807d4 (plain) (tree)
1
2
3
4
5
6
7
8

                                                                          
                                                                          
                                                                          

                                                                          

                                                                          


       
                        
 
                
 




                                                                                              
                                   

                                       




                                                                                                 
  






                                                                                                
   

                                                                             
 
 

                                                       
                                                            
                                                                                                          
 
/*                     __                                               *\
**     ________ ___   / /  ___     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 iterator: 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]
}