Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutable.Buffer.remove(index, count) is inconsistent with mutable.Buffer.remove(index) #9882

Open
scabug opened this issue Aug 7, 2016 · 2 comments

Comments

@scabug
Copy link

scabug commented Aug 7, 2016

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.

@scabug
Copy link
Author

scabug commented Aug 7, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9882?orig=1
Reporter: Pathikrit Bhowmick (pathikritbhowmick-at-msn.com)

@scabug
Copy link
Author

scabug commented Aug 8, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants