diff options
author | Paul Phillips <paulp@improving.org> | 2010-12-03 07:17:57 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-12-03 07:17:57 +0000 |
commit | ff8932a4297e4b0439897edf5e47020d60dcb5a6 (patch) | |
tree | ea07aa9725f209ce4beb5b3a4f94bf1d7d99bffd /src | |
parent | 13182292f247123391eea0e2c62a7fdb6b389c23 (diff) | |
download | scala-ff8932a4297e4b0439897edf5e47020d60dcb5a6.tar.gz scala-ff8932a4297e4b0439897edf5e47020d60dcb5a6.tar.bz2 scala-ff8932a4297e4b0439897edf5e47020d60dcb5a6.zip |
Recovered ++: from the dustbin and dropped it o...
Recovered ++: from the dustbin and dropped it on Traversable. Removed
a very unfortunate deprecated method from BufferLike which it was not
authorized to deprecate because it's a Seq. Closes #3471, review by
prokopec.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/TraversableLike.scala | 32 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/BufferLike.scala | 25 |
2 files changed, 32 insertions, 25 deletions
diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index c4765fb89e..116db7dc7d 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -186,6 +186,38 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] b.result } + /** Concatenates this $coll with the elements of a traversable collection. It + * differs from ++ in that the right operand determines the type of the resulting + * collection rather than the left one. + * + * @param that the traversable to append. + * @tparam B the element type of the returned collection. + * @tparam That $thatinfo + * @param bf $bfinfo + * @return a new collection of type `That` which contains all elements of this $coll + * followed by all elements of `that`. + * + * @usecase def ++(that: TraversableOnce[A]): $Coll[A] + * + * @return a new $coll which contains all elements of this $coll + * followed by all elements of `that`. + */ + def ++:[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { + val b = bf(repr) + if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.size) + b ++= that + b ++= thisCollection + b.result + } + + /** This overload exists because: for the implementation of ++: we should reuse + * that of ++ because many collections override it with more efficient versions. + * Since TraversableOnce has no '++' method, we have to implement that directly, + * but Traversable and down can use the overload. + */ + def ++:[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = + (that ++ this)(breakOut) + /** Builds a new collection by applying a function to all elements of this $coll. * * @param f the function to apply to each element. diff --git a/src/library/scala/collection/mutable/BufferLike.scala b/src/library/scala/collection/mutable/BufferLike.scala index 3654dd82fa..32c666ea58 100644 --- a/src/library/scala/collection/mutable/BufferLike.scala +++ b/src/library/scala/collection/mutable/BufferLike.scala @@ -233,31 +233,6 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]] } } - - /** This method prepends elements to the buffer and - * returns the same buffer. - * - * $compatMutate - * You are strongly recommended to use `++=:` instead. - * - * @param xs elements to prepend - * @return this buffer - */ - @deprecated("use ++=: instead") - final def ++:(xs: collection.Traversable[A]): This = ++=:(xs) - - /** This method prepends elements to the buffer and - * returns the same buffer. - * - * $compatMutate - * You are strongly recommended to use `+=:` instead. - * - * @param xs elements to prepend - * @return this buffer - */ - @deprecated("use `+=:' instead") - final def +:(elem: A): This = +=:(elem) - /** Adds a single element to this collection and returns * the collection itself. * |