summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-03-22 18:22:21 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-03-22 18:22:21 +0000
commit60d9a5127cf190c90e2e3ce4f79455469dac54eb (patch)
tree7b3fc90e50b1086459db9f38d6f58875bc1a8e21 /src/library
parentfda6c9517efc154c8516acaf139f4a547a9e4575 (diff)
downloadscala-60d9a5127cf190c90e2e3ce4f79455469dac54eb.tar.gz
scala-60d9a5127cf190c90e2e3ce4f79455469dac54eb.tar.bz2
scala-60d9a5127cf190c90e2e3ce4f79455469dac54eb.zip
Adding the `seq` method to all collections.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/Map.scala2
-rw-r--r--src/library/scala/collection/Seq.scala2
-rw-r--r--src/library/scala/collection/Sequentializable.scala15
-rw-r--r--src/library/scala/collection/Sequentializable.scala.disabled10
-rw-r--r--src/library/scala/collection/Set.scala2
-rw-r--r--src/library/scala/collection/TraversableOnce.scala16
-rw-r--r--src/library/scala/collection/immutable/Map.scala2
-rw-r--r--src/library/scala/collection/immutable/Seq.scala1
-rw-r--r--src/library/scala/collection/immutable/Set.scala1
-rw-r--r--src/library/scala/collection/mutable/Map.scala2
-rw-r--r--src/library/scala/collection/mutable/Seq.scala1
-rw-r--r--src/library/scala/collection/mutable/Set.scala1
-rw-r--r--src/library/scala/collection/parallel/ParIterableLike.scala10
13 files changed, 46 insertions, 19 deletions
diff --git a/src/library/scala/collection/Map.scala b/src/library/scala/collection/Map.scala
index 18c8c0d174..075317a483 100644
--- a/src/library/scala/collection/Map.scala
+++ b/src/library/scala/collection/Map.scala
@@ -28,6 +28,8 @@ import generic._
*/
trait Map[A, +B] extends Iterable[(A, B)] with MapLike[A, B, Map[A, B]] {
def empty: Map[A, B] = Map.empty
+
+ override def seq: Map[A, B] = this
}
/** $factoryInfo
diff --git a/src/library/scala/collection/Seq.scala b/src/library/scala/collection/Seq.scala
index 791f41354b..bbf392ab32 100644
--- a/src/library/scala/collection/Seq.scala
+++ b/src/library/scala/collection/Seq.scala
@@ -21,6 +21,8 @@ trait Seq[+A] extends PartialFunction[Int, A]
with GenericTraversableTemplate[A, Seq]
with SeqLike[A, Seq[A]] {
override def companion: GenericCompanion[Seq] = Seq
+
+ override def seq: Seq[A] = this
}
/** $factoryInfo
diff --git a/src/library/scala/collection/Sequentializable.scala b/src/library/scala/collection/Sequentializable.scala
deleted file mode 100644
index 61fb24571a..0000000000
--- a/src/library/scala/collection/Sequentializable.scala
+++ /dev/null
@@ -1,15 +0,0 @@
-package scala.collection
-
-
-
-
-trait Sequentializable[+T, +Repr] {
-
- /** A view of this parallel collection, but with all
- * of the operations implemented sequentially (i.e. in a single-threaded manner).
- *
- * @return a sequential view of the collection.
- */
- def seq: Repr
-
-} \ No newline at end of file
diff --git a/src/library/scala/collection/Sequentializable.scala.disabled b/src/library/scala/collection/Sequentializable.scala.disabled
new file mode 100644
index 0000000000..df457671a6
--- /dev/null
+++ b/src/library/scala/collection/Sequentializable.scala.disabled
@@ -0,0 +1,10 @@
+package scala.collection
+
+
+
+
+trait Sequentializable[+T, +Repr] {
+
+ def seq: Repr
+
+}
diff --git a/src/library/scala/collection/Set.scala b/src/library/scala/collection/Set.scala
index 412ebf0e25..f89df50f26 100644
--- a/src/library/scala/collection/Set.scala
+++ b/src/library/scala/collection/Set.scala
@@ -27,6 +27,8 @@ trait Set[A] extends (A => Boolean)
with GenericSetTemplate[A, Set]
with SetLike[A, Set[A]] {
override def companion: GenericCompanion[Set] = Set
+
+ override def seq: Set[A] = this
}
/** $factoryInfo
diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala
index de3b4770f3..a062d5710d 100644
--- a/src/library/scala/collection/TraversableOnce.scala
+++ b/src/library/scala/collection/TraversableOnce.scala
@@ -81,6 +81,22 @@ trait TraversableOnce[+A] {
*/
def toStream: Stream[A]
+ // Note: We could redefine this in TraversableLike to always return `repr`
+ // of type `Repr`, only if `Repr` had type bounds, which it doesn't, because
+ // not all `Repr` are a subtype `TraversableOnce[A]`.
+ // The alternative is redefining it for maps, sets and seqs. For concrete implementations
+ // we don't have to do this anyway, since they are leaves in the inheritance hierarchy.
+ /** A version of this collection with all
+ * of the operations implemented sequentially (i.e. in a single-threaded manner).
+ *
+ * This method returns a reference to this collection. In parallel collections,
+ * it is redefined to return a sequential implementation of this collection. In
+ * both cases, it has O(1) complexity.
+ *
+ * @return a sequential view of the collection.
+ */
+ def seq: TraversableOnce[A] = this
+
/** Presently these are abstract because the Traversable versions use
* breakable/break, and I wasn't sure enough of how that's supposed to
* function to consolidate them with the Iterator versions.
diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala
index 69e1f38548..2c7c1023ed 100644
--- a/src/library/scala/collection/immutable/Map.scala
+++ b/src/library/scala/collection/immutable/Map.scala
@@ -33,6 +33,8 @@ trait Map[A, +B] extends Iterable[(A, B)]
override def toMap[T, U](implicit ev: (A, B) <:< (T, U)): immutable.Map[T, U] =
self.asInstanceOf[immutable.Map[T, U]]
+ override def seq: Map[A, B] = this
+
/** The same map with a given default function.
* Note: `get`, `contains`, `iterator`, `keys`, etc are not affected by `withDefault`.
*
diff --git a/src/library/scala/collection/immutable/Seq.scala b/src/library/scala/collection/immutable/Seq.scala
index 4f061983de..0a370615fc 100644
--- a/src/library/scala/collection/immutable/Seq.scala
+++ b/src/library/scala/collection/immutable/Seq.scala
@@ -30,6 +30,7 @@ trait Seq[+A] extends Iterable[A]
override def companion: GenericCompanion[Seq] = Seq
override def toSeq: Seq[A] = this
protected[this] override def parCombiner = ParSeq.newCombiner[A] // if `immutable.SeqLike` gets introduced, please move this there!
+ override def seq: Seq[A] = this
}
/** $factoryInfo
diff --git a/src/library/scala/collection/immutable/Set.scala b/src/library/scala/collection/immutable/Set.scala
index 1b61c6f565..7975134174 100644
--- a/src/library/scala/collection/immutable/Set.scala
+++ b/src/library/scala/collection/immutable/Set.scala
@@ -33,6 +33,7 @@ trait Set[A] extends Iterable[A]
override def companion: GenericCompanion[Set] = Set
override def toSet[B >: A]: Set[B] = this.asInstanceOf[Set[B]]
protected override def parCombiner = ParSet.newCombiner[A] // if `immutable.SetLike` gets introduced, please move this there!
+ override def seq: Set[A] = this
}
/** $factoryInfo
diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala
index e4fe4dfa1a..28e0ca2bcf 100644
--- a/src/library/scala/collection/mutable/Map.scala
+++ b/src/library/scala/collection/mutable/Map.scala
@@ -26,6 +26,8 @@ trait Map[A, B]
override def empty: Map[A, B] = Map.empty
+ override def seq: Map[A, B] = this
+
/** The same map with a given default function.
*
* Invoking transformer methods (e.g. `map`) will not preserve the default value.
diff --git a/src/library/scala/collection/mutable/Seq.scala b/src/library/scala/collection/mutable/Seq.scala
index 432c242060..8e7019c755 100644
--- a/src/library/scala/collection/mutable/Seq.scala
+++ b/src/library/scala/collection/mutable/Seq.scala
@@ -29,6 +29,7 @@ trait Seq[A] extends Iterable[A]
with GenericTraversableTemplate[A, Seq]
with SeqLike[A, Seq[A]] {
override def companion: GenericCompanion[Seq] = Seq
+ override def seq: Seq[A] = this
}
/** $factoryInfo
diff --git a/src/library/scala/collection/mutable/Set.scala b/src/library/scala/collection/mutable/Set.scala
index 1bc10247d6..8d0588e5b9 100644
--- a/src/library/scala/collection/mutable/Set.scala
+++ b/src/library/scala/collection/mutable/Set.scala
@@ -24,6 +24,7 @@ trait Set[A] extends Iterable[A]
with GenericSetTemplate[A, Set]
with SetLike[A, Set[A]] {
override def companion: GenericCompanion[Set] = Set
+ override def seq: Set[A] = this
}
/** $factoryInfo
diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala
index 6b7f244867..92c7d5ac97 100644
--- a/src/library/scala/collection/parallel/ParIterableLike.scala
+++ b/src/library/scala/collection/parallel/ParIterableLike.scala
@@ -17,7 +17,6 @@ import scala.collection.mutable.ArrayBuffer
import scala.collection.IterableLike
import scala.collection.Parallel
import scala.collection.CustomParallelizable
-import scala.collection.Sequentializable
import scala.collection.generic._
import immutable.HashMapCombiner
@@ -160,14 +159,15 @@ import annotation.unchecked.uncheckedVariance
trait ParIterableLike[+T, +Repr <: ParIterable[T], +Sequential <: Iterable[T] with IterableLike[T, Sequential]]
extends IterableLike[T, Repr]
with CustomParallelizable[T, Repr]
- with Sequentializable[T, Sequential]
with Parallel
with HasNewCombiner[T, Repr]
{
-self =>
+self: ParIterableLike[T, Repr, Sequential] =>
import tasksupport._
+ override def seq: Sequential = throw new UnsupportedOperationException("not implemented.")
+
/** Parallel iterators are split iterators that have additional accessor and
* transformer methods defined in terms of methods `next` and `hasNext`.
* When creating a new parallel collection, one might want to override these
@@ -421,6 +421,7 @@ self =>
executeAndWaitResult(new Aggregate(z, seqop, combop, parallelIterator))
}
+ /*
/** Applies a function `f` to all the elements of $coll. Does so in a nondefined order,
* and in parallel.
*
@@ -432,6 +433,7 @@ self =>
def pforeach[U](f: T => U): Unit = {
executeAndWaitResult(new Foreach(f, parallelIterator))
}
+ */
/** Applies a function `f` to all the elements of $coll in a sequential order.
*
@@ -731,7 +733,7 @@ self =>
override def view = new ParIterableView[T, Repr, Sequential] {
protected lazy val underlying = self.repr
- def seq = self.seq.view
+ override def seq = self.seq.view
def parallelIterator = self.parallelIterator
}