diff options
author | Josh Suereth <joshua.suereth@gmail.com> | 2012-06-18 11:43:18 -0400 |
---|---|---|
committer | Josh Suereth <joshua.suereth@gmail.com> | 2012-06-18 11:43:56 -0400 |
commit | f559505c1f254c98ae34bb4cdf1e2b624d25a84c (patch) | |
tree | dc1297564648f326a4361e44fdff9fdc440671b0 /src/library/scala/collection/GenTraversableOnce.scala | |
parent | 89f83568709c01348d34262fa9e408a252c6300e (diff) | |
download | scala-f559505c1f254c98ae34bb4cdf1e2b624d25a84c.tar.gz scala-f559505c1f254c98ae34bb4cdf1e2b624d25a84c.tar.bz2 scala-f559505c1f254c98ae34bb4cdf1e2b624d25a84c.zip |
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.
Diffstat (limited to 'src/library/scala/collection/GenTraversableOnce.scala')
-rw-r--r-- | src/library/scala/collection/GenTraversableOnce.scala | 19 |
1 files changed, 19 insertions, 0 deletions
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] } |