You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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.
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.The text was updated successfully, but these errors were encountered: