summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/TraversableLike.scala
diff options
context:
space:
mode:
authorJosh Suereth <joshua.suereth@gmail.com>2012-06-18 11:43:18 -0400
committerJosh Suereth <joshua.suereth@gmail.com>2012-06-18 11:43:56 -0400
commitf559505c1f254c98ae34bb4cdf1e2b624d25a84c (patch)
treedc1297564648f326a4361e44fdff9fdc440671b0 /src/library/scala/collection/TraversableLike.scala
parent89f83568709c01348d34262fa9e408a252c6300e (diff)
downloadscala-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/TraversableLike.scala')
-rw-r--r--src/library/scala/collection/TraversableLike.scala7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala
index 3716a318d9..898ea4d654 100644
--- a/src/library/scala/collection/TraversableLike.scala
+++ b/src/library/scala/collection/TraversableLike.scala
@@ -616,6 +616,13 @@ trait TraversableLike[+A, +Repr] extends Any
def toTraversable: Traversable[A] = thisCollection
def toIterator: Iterator[A] = toStream.iterator
def toStream: Stream[A] = toBuffer.toStream
+ def toVector: Vector[A] = copyInto[Vector]
+ def copyInto[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A @uV]]): Col[A @uV] = {
+ val b = cbf()
+ b.sizeHint(this)
+ b ++= thisCollection
+ b.result
+ }
/** Converts this $coll to a string.
*