diff options
author | Paul Phillips <paulp@improving.org> | 2010-03-22 22:09:58 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-03-22 22:09:58 +0000 |
commit | 4eff9e1cd51202b8c3bf7c8e0fe176a05f4d4acd (patch) | |
tree | 944d9c77890c17ff7b9192e05ece9c4130f8113a /src/library/scala/collection/mutable/GrowingBuilder.scala | |
parent | a263215e095d8168ed78b16c829a56ff48b2f9b6 (diff) | |
download | scala-4eff9e1cd51202b8c3bf7c8e0fe176a05f4d4acd.tar.gz scala-4eff9e1cd51202b8c3bf7c8e0fe176a05f4d4acd.tar.bz2 scala-4eff9e1cd51202b8c3bf7c8e0fe176a05f4d4acd.zip |
Consistency work on Addable and Growable.
Seq-derived classes. Creating GrowingBuilder to complement AddingBuilder
on classes with += but not +. Fixed some inconsistencies I came across
in the process. No review.
Diffstat (limited to 'src/library/scala/collection/mutable/GrowingBuilder.scala')
-rw-r--r-- | src/library/scala/collection/mutable/GrowingBuilder.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/library/scala/collection/mutable/GrowingBuilder.scala b/src/library/scala/collection/mutable/GrowingBuilder.scala new file mode 100644 index 0000000000..259df9a434 --- /dev/null +++ b/src/library/scala/collection/mutable/GrowingBuilder.scala @@ -0,0 +1,30 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2010, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection +package mutable + +import generic._ + +/** The canonical builder for collections that are growable, i.e. that support an + * efficient `+=` method which adds an element to the collection. It is + * almost identical to AddingBuilder, but necessitated by the existence of + * classes which are Growable but not Addable, which is a result of covariance + * interacting surprisingly with any2stringadd thus driving '+' out of the Seq + * hierachy. The tendrils of original sin should never be underestimated. + * + * @author Paul Phillips + * @version 2.8 + * @since 2.8 + */ +class GrowingBuilder[Elem, To <: Growable[Elem]](empty: To) extends Builder[Elem, To] { + protected var elems: To = empty + def +=(x: Elem): this.type = { elems += x; this } + def clear() { elems = empty } + def result: To = elems +} |