bug
bug copied to clipboard
mutable.Buffer.remove(index, count) is inconsistent with mutable.Buffer.remove(index)
The mutable.BufferLike has this nice remove method which returns the removed item as well as mutating the mutable collection:
def remove(index: Int): A
But, it also has this remove method which takes in a count but does NOT return back the removed items:
def remove(index: Int, count: Int): Unit
The above method should not return an Unit but the list of removed items.
See: https://github.com/scala/scala/blob/5562e1a2eb07b9a541b3eac85a809847e2d48763/src/library/scala/collection/mutable/BufferLike.scala#L106-L121
All we need to do is to change the lines for (i <- 0 until count) remove(n) to (0 until count).map(i => remove(n))
This change should be backwards compatible since it was earlier returning an Unit anyway.
Imported From: https://issues.scala-lang.org/browse/SI-9882?orig=1 Reporter: Pathikrit Bhowmick (pathikritbhowmick-at-msn.com)
@SethTisue said:
Note that the workaround is to call slice first, before remove.
I guess if we made this change, the result type ought to match slice's result type, so your proposed code change would need some refinement.
It's not a no-brainer that this change is desirable; single-element remove never needs to allocate, but multi-element remove would have to allocate. If the return value is usually ignored, then allocating is undesirable.