diff options
author | Paul Phillips <paulp@improving.org> | 2010-03-22 23:02:50 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-03-22 23:02:50 +0000 |
commit | 88aab1cf8e06f98ccd18437974c09162ee54149f (patch) | |
tree | aafd69e2e195fb63341d4a01ffa90ced19cec0d9 /src | |
parent | 4eff9e1cd51202b8c3bf7c8e0fe176a05f4d4acd (diff) | |
download | scala-88aab1cf8e06f98ccd18437974c09162ee54149f.tar.gz scala-88aab1cf8e06f98ccd18437974c09162ee54149f.tar.bz2 scala-88aab1cf8e06f98ccd18437974c09162ee54149f.zip |
Noticed we still have a bunch of collection cla...
Noticed we still have a bunch of collection classes which are rather
lacking. Did some integration, added some companion objects. Not
thrilled with the overall picture in there, there's still a lot which
should be done. Updated a deprecation message, closes #3202. No review.
Diffstat (limited to 'src')
9 files changed, 36 insertions, 39 deletions
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index 6e4c1ffe37..fcc8ad726e 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -569,9 +569,9 @@ object List extends SeqFactory[List] { * @param xs the iterable of Eithers to separate * @return a pair of lists. */ - @deprecated("use `Either.separate' instead") + @deprecated("use `(for (Left(x) <- es) yield x, for (Right(x) <- es) yield x)` instead") def separate[A,B](es: Iterable[Either[A, B]]): (List[A], List[B]) = - es.foldRight[(List[A], List[B])]((Nil, Nil)) { + es.foldRight[(List[A], List[B])]((Nil, Nil)) { case (Left(a), (lefts, rights)) => (a :: lefts, rights) case (Right(b), (lefts, rights)) => (lefts, b :: rights) } diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 9957f90ab3..02d344ceea 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -12,12 +12,8 @@ package scala.collection package immutable -import scala.annotation.tailrec - -object Queue { - val Empty: Queue[Nothing] = new Queue(Nil, Nil) - def apply[A](elems: A*) = new Queue(Nil, elems.toList) -} +import generic._ +import mutable.{ Builder, ListBuffer } /** <code>Queue</code> objects implement data structures that allow to * insert and retrieve elements in a first-in-first-out (FIFO) manner. @@ -28,10 +24,13 @@ object Queue { */ @serializable @SerialVersionUID(-7622936493364270175L) -class Queue[+A] protected( - protected val in: List[A], - protected val out: List[A]) extends Seq[A] -{ +class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) + extends Seq[A] + with GenericTraversableTemplate[A, Queue] + with SeqLike[A, Queue[A]] { + + override def companion: GenericCompanion[Queue] = Queue + /** Returns the <code>n</code>-th element of this queue. * The first element is at position 0. * @@ -127,3 +126,13 @@ class Queue[+A] protected( */ override def toString() = mkString("Queue(", ", ", ")") } + +object Queue extends SeqFactory[Queue] { + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Queue[A]] = new GenericCanBuildFrom[A] + def newBuilder[A]: Builder[A, Queue[A]] = new ListBuffer[A] mapResult (x => new Queue[A](Nil, x.toList)) + override def empty[A]: Queue[A] = new Queue[A](Nil, Nil) + override def apply[A](xs: A*): Queue[A] = new Queue[A](Nil, xs.toList) + + @deprecated("Use Queue.empty instead") + val Empty: Queue[Nothing] = Queue() +} diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala index 1a3ed38e1c..79e1a6b00b 100644 --- a/src/library/scala/collection/immutable/TreeSet.scala +++ b/src/library/scala/collection/immutable/TreeSet.scala @@ -19,8 +19,7 @@ import mutable.{Builder, AddingBuilder} * * @since 1 */ -object TreeSet extends SortedSetFactory[TreeSet]{ - +object TreeSet extends SortedSetFactory[TreeSet] { implicit def implicitBuilder[A](implicit ordering: Ordering[A]): Builder[A, TreeSet[A]] = newBuilder[A](ordering) override def newBuilder[A](implicit ordering: Ordering[A]): Builder[A, TreeSet[A]] = new AddingBuilder(empty[A](ordering)) @@ -28,7 +27,6 @@ object TreeSet extends SortedSetFactory[TreeSet]{ /** The empty set of this type */ def empty[A](implicit ordering: Ordering[A]) = new TreeSet[A] - } /** This class implements immutable sets using a tree. diff --git a/src/library/scala/collection/mutable/ConcurrentMap.scala b/src/library/scala/collection/mutable/ConcurrentMap.scala index d09bf57e1b..2cfa4f8ae2 100644 --- a/src/library/scala/collection/mutable/ConcurrentMap.scala +++ b/src/library/scala/collection/mutable/ConcurrentMap.scala @@ -1,9 +1,5 @@ -package scala.collection.mutable - - - - - +package scala.collection +package mutable /** * A template trait for mutable maps that allow concurrent access. @@ -66,14 +62,4 @@ trait ConcurrentMap[A, B] extends Map[A, B] { * @return `Some(v)` if the given key was previously mapped to some value `v`, or `None` otherwise */ def replace(k: A, v: B): Option[B] - } - - - - - - - - - diff --git a/src/library/scala/collection/mutable/DoubleLinkedList.scala b/src/library/scala/collection/mutable/DoubleLinkedList.scala index 8c50f739e1..718d6aa35d 100644 --- a/src/library/scala/collection/mutable/DoubleLinkedList.scala +++ b/src/library/scala/collection/mutable/DoubleLinkedList.scala @@ -40,7 +40,7 @@ class DoubleLinkedList[A]() extends LinearSeq[A] } object DoubleLinkedList extends SeqFactory[DoubleLinkedList] { - implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, DoubleLinkedList[A]] = new GenericCanBuildFrom[A] //new CanBuildFrom[Coll, A, DoubleLinkedList[A]] { : Coll) = from.traversableBuilder[A] } + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, DoubleLinkedList[A]] = new GenericCanBuildFrom[A] def newBuilder[A]: Builder[A, DoubleLinkedList[A]] = new Builder[A, DoubleLinkedList[A]] { var current: DoubleLinkedList[A] = _ diff --git a/src/library/scala/collection/mutable/OpenHashMap.scala b/src/library/scala/collection/mutable/OpenHashMap.scala index 9f0d9d2c25..79bb96a0bf 100644 --- a/src/library/scala/collection/mutable/OpenHashMap.scala +++ b/src/library/scala/collection/mutable/OpenHashMap.scala @@ -15,7 +15,7 @@ package mutable /** * @since 2.7 */ -object OpenHashMap{ +object OpenHashMap { def apply[K, V](elems : (K, V)*) = { val dict = new OpenHashMap[K, V]; elems.foreach({case (x, y) => dict(x) = y}); diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index 8782d09c73..96d60ce4ea 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -279,4 +279,4 @@ class PriorityQueue[A](implicit ord: Ordering[A]) // def empty[A](implicit ord: Ordering[A]): PriorityQueue[A] = new PriorityQueue[A](ord) // implicit def canBuildFrom[A](implicit ord: Ordering[A]): CanBuildFrom[Coll, A, PriorityQueue] = // } -// +//
\ No newline at end of file diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala index 6b32f0f94e..3754dbc3f2 100644 --- a/src/library/scala/collection/mutable/Queue.scala +++ b/src/library/scala/collection/mutable/Queue.scala @@ -144,8 +144,7 @@ class Queue[A] extends MutableList[A] with Cloneable[Queue[A]] { def front: A = first0.elem } -// !!! TODO -// object Queue extends SeqFactory[Queue] { -// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Queue[A]] = new GenericCanBuildFrom[A] -// def newBuilder[A]: Builder[A, Queue[A]] = new GrowingBuilder(new Queue[A]) -// } +// !!! TODO - integrate +object Queue { + def apply[A](xs: A*): Queue[A] = new Queue[A] ++= xs +} diff --git a/src/library/scala/collection/mutable/Stack.scala b/src/library/scala/collection/mutable/Stack.scala index 8f626e7f33..d26c2f3176 100644 --- a/src/library/scala/collection/mutable/Stack.scala +++ b/src/library/scala/collection/mutable/Stack.scala @@ -137,3 +137,8 @@ class Stack[A] private (var elems: List[A]) extends scala.collection.Seq[A] with */ override def clone(): Stack[A] = new Stack[A](elems) } + +// !!! TODO - integrate +object Stack { + def apply[A](xs: A*): Stack[A] = new Stack[A] ++= xs +} |