diff options
author | stepancheg <stepancheg@epfl.ch> | 2008-05-27 13:27:03 +0000 |
---|---|---|
committer | stepancheg <stepancheg@epfl.ch> | 2008-05-27 13:27:03 +0000 |
commit | 0d82294aa63727bf3e4612e4330769929a1dd788 (patch) | |
tree | 19497eb5dba752d61aee0cbdbe9807f1935de1f7 /src | |
parent | 6f638318d68d360157b87861842ad5f3b9e04079 (diff) | |
download | scala-0d82294aa63727bf3e4612e4330769929a1dd788.tar.gz scala-0d82294aa63727bf3e4612e4330769929a1dd788.tar.bz2 scala-0d82294aa63727bf3e4612e4330769929a1dd788.zip |
Iterator.collect method (#916)
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/Iterator.scala | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/library/scala/Iterator.scala b/src/library/scala/Iterator.scala index fe57853d4f..517664cdfc 100644 --- a/src/library/scala/Iterator.scala +++ b/src/library/scala/Iterator.scala @@ -13,7 +13,7 @@ package scala import Predef._ -import collection.mutable.{Buffer, ListBuffer} +import collection.mutable.{Buffer, ListBuffer, ArrayBuffer} /** The <code>Iterator</code> object provides various functions for * creating specialized iterators. @@ -678,6 +678,16 @@ trait Iterator[+A] { res.toList } + /** Collect elements into a seq. + * + * @return a seq which enumerates all elements of this iterator. + */ + def collect: Seq[A] = { + val buffer = new ArrayBuffer[A] + this copyToBuffer buffer + buffer.readOnly + } + /** Returns a string representation of the elements in this iterator. The resulting string * begins with the string <code>start</code> and is finished by the string * <code>end</code>. Inside, the string representations of elements (w.r.t. |