From 0d82294aa63727bf3e4612e4330769929a1dd788 Mon Sep 17 00:00:00 2001 From: stepancheg Date: Tue, 27 May 2008 13:27:03 +0000 Subject: Iterator.collect method (#916) --- src/library/scala/Iterator.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') 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 Iterator 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 start and is finished by the string * end. Inside, the string representations of elements (w.r.t. -- cgit v1.2.3