Skip to content

Commit 681afff

Browse files
committed
Add deprecated copyToBuffer operation to IterableOnceOps
Fixes scala/collection-strawman#538
1 parent b784d65 commit 681afff

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/library/scala/collection/IterableOnce.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
617617
}
618618
}
619619

620+
@deprecated("Use `dest ++= coll` instead", "2.13.0")
621+
@inline final def copyToBuffer[B >: A](dest: mutable.Buffer[B]): Unit = dest ++= this
622+
620623
/** Copy elements of this collection to an array.
621624
* Fills the given array `xs` starting at index `start`.
622625
* Copying will stop once either the all elements of this collection have been copied,

test/junit/scala/collection/TraversableOnceTest.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,13 @@ class TraversableOnceTest {
6767
assert(evaluatedCountOfMinBy == list.length, s"minBy: should evaluate f only ${list.length} times, but it evaluated $evaluatedCountOfMinBy times.")
6868
}
6969

70+
@Test
71+
def copyToBuffer(): Unit = {
72+
val b1 = mutable.ArrayBuffer.empty[Int]
73+
list.copyToBuffer(b1)
74+
val b2 = mutable.ArrayBuffer.empty[Int]
75+
b2 ++= list
76+
assert(b1 == b2)
77+
}
78+
7079
}

0 commit comments

Comments
 (0)