summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNAME <USER@epfl.ch>2008-03-18 19:41:25 +0000
committerNAME <USER@epfl.ch>2008-03-18 19:41:25 +0000
commite76edeb541685b342433a4a2b3683e11d579b37a (patch)
treee3a23d64ebd47d01dcaad70b035e897c798e1955
parentdf542644b4384b0b19e752174277f1a2bb72c66a (diff)
downloadscala-e76edeb541685b342433a4a2b3683e11d579b37a.tar.gz
scala-e76edeb541685b342433a4a2b3683e11d579b37a.tar.bz2
scala-e76edeb541685b342433a4a2b3683e11d579b37a.zip
Enhancement #623
-rw-r--r--src/library/scala/Iterable.scala10
-rw-r--r--src/library/scala/Seq.scala7
2 files changed, 15 insertions, 2 deletions
diff --git a/src/library/scala/Iterable.scala b/src/library/scala/Iterable.scala
index a3fd4ca6d4..9cf18f3b46 100644
--- a/src/library/scala/Iterable.scala
+++ b/src/library/scala/Iterable.scala
@@ -408,13 +408,19 @@ trait Iterable[+A] {
}
/**
- * Create a fresh list with all the elements of this iterable object.
+ * Returns a list containing all of the elements in this iterable object.
* @note Will not terminate for infinite-sized collections.
*/
def toList: List[A] = elements.toList
/**
- * Create a stream which contains all the elements of this iterable object.
+ * Returns a sequence containing all of the elements in this iterable object.
+ * @note Will not terminate for infinite-sized collections.
+ */
+ def toSeq: Seq[A] = toList
+
+ /**
+ * Returns a stream containing all of the elements in this iterable object.
* @note consider using <code>projection</code> for lazy behavior.
*/
def toStream: Stream[A] = Stream.fromIterator(elements)
diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala
index ce619944f9..bc075fb745 100644
--- a/src/library/scala/Seq.scala
+++ b/src/library/scala/Seq.scala
@@ -375,6 +375,13 @@ trait Seq[+A] extends AnyRef with PartialFunction[Int, A] with Collection[A] {
result
}
+ /**
+ * Overridden for efficiency.
+ *
+ * @return the sequence itself
+ */
+ override def toSeq: Seq[A] = this
+
override def projection: Seq.Projection[A] = new Seq.Projection[A] {
override def force: Seq[A] = Seq.this
def elements = Seq.this.elements