summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/MapBuilder.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-09-25 16:20:13 +0000
committerMartin Odersky <odersky@gmail.com>2009-09-25 16:20:13 +0000
commit4a727f3b01d0fa27ef51f7dba472116e021e3445 (patch)
treec9ab55ea7fe6051455271b23e9fbfc2f313015c0 /src/library/scala/collection/mutable/MapBuilder.scala
parente31f18094dfba97c80871869a037172ff2c9c1c2 (diff)
downloadscala-4a727f3b01d0fa27ef51f7dba472116e021e3445.tar.gz
scala-4a727f3b01d0fa27ef51f7dba472116e021e3445.tar.bz2
scala-4a727f3b01d0fa27ef51f7dba472116e021e3445.zip
Collections refactoring.
Diffstat (limited to 'src/library/scala/collection/mutable/MapBuilder.scala')
-rw-r--r--src/library/scala/collection/mutable/MapBuilder.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/library/scala/collection/mutable/MapBuilder.scala b/src/library/scala/collection/mutable/MapBuilder.scala
new file mode 100644
index 0000000000..bcbd50c44e
--- /dev/null
+++ b/src/library/scala/collection/mutable/MapBuilder.scala
@@ -0,0 +1,31 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.collection
+package mutable
+
+/** The canonical builder for immutable maps, working with the map's `+` method
+ * to add new elements.
+ * Collections are built from their `empty` element using this + method.
+ * @param empty The empty element of the collection.
+ */
+class MapBuilder[A, B, Coll <: scala.collection.Map[A, B] with scala.collection.MapLike[A, B, Coll]](empty: Coll)
+extends Builder[(A, B), Coll] {
+ protected var elems: Coll = empty
+ def +=(x: (A, B)): this.type = {
+ elems = (elems + x).asInstanceOf[Coll]
+ // the cast is necessary because right now we cannot enforce statically that
+ // for every map of type Coll, `+` yields again a Coll. With better support
+ // for hk-types we might be able to enforce this in the future, though.
+ this
+ }
+ def clear() { elems = empty }
+ def result: Coll = elems
+}