From ff8932a4297e4b0439897edf5e47020d60dcb5a6 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 3 Dec 2010 07:17:57 +0000 Subject: 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. --- src/library/scala/collection/TraversableLike.scala | 32 ++++++++++++++++++++++ .../scala/collection/mutable/BufferLike.scala | 25 ----------------- 2 files changed, 32 insertions(+), 25 deletions(-) (limited to 'src/library') 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. * -- cgit v1.2.3