From f559505c1f254c98ae34bb4cdf1e2b624d25a84c Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 18 Jun 2012 11:43:18 -0400 Subject: Adding copyInto and toVector methods to collections. * Added generic copyInto method for collections. For any collection with a CanBuildFrom, can convert a generic collection into it using the builder. * Added specifici toVector method for collections. This is more efficient than copyInto if the collection is a Vector. --- src/library/scala/collection/GenTraversableOnce.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/library/scala/collection/GenTraversableOnce.scala') diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index eadacd9209..d22fb0f3ad 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -9,6 +9,8 @@ package scala.collection import scala.reflect.ClassTag +import scala.collection.generic.CanBuildFrom +import scala.annotation.unchecked.{ uncheckedVariance => uV } /** A template trait for all traversable-once objects which may be * traversed in parallel. @@ -552,4 +554,21 @@ trait GenTraversableOnce[+A] extends Any { * containing all key/value pairs of type `(T, U)` of this $coll. */ def toMap[K, V](implicit ev: A <:< (K, V)): GenMap[K, V] + + /** Converts this $coll to a Vector. + * $willNotTerminateInf + * @return a vector containing all elements of this $coll. + */ + def toVector: Vector[A] + + /** Converts this $coll into another by copying all elemnents. + * $willNotTerminateInf + * @return a new collection containing all elements of this $coll. + * + * @usecase def copyInto[Col[_]]: Col[A] + * @inheritdoc + * $willNotTerminateInf + * @return a new collection containing all elemnts of this $coll. + */ + def copyInto[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A @uV]]): Col[A @uV] } -- cgit v1.2.3