Closed hosseinhaeri closed 6 years ago
Note that you could avoid the creation of a temporary collection as follows:
myListBuffer --= myListBuffer.view.drop(myListBuffer.size - n)
But still, it would be more convenient to have high-level operations to trim Shrinkable
collections.
Thanks. I wasn't actually aware of the view
facility. I will use that for now. But, I'll look forward the convenient syntax.
ListBuffer
does have a dropRightInPlace
method defined. Is the issue to create the --=
alias for dropRightInPlace
?
Actually I forgot to check but all Buffer
s have dropRightInPlace
: https://static.javadoc.io/ch.epfl.scala/collection-strawman_2.13.0-M2/0.9.0/strawman/collection/mutable/Buffer.html#dropRightInPlace(n:Int):Buffer.this.type
Thank you for pointing out dropRightInPlace
. It would be of even more interest to have that alised into --=
too.
ListBuffer
does have the familiardropRight
method. It also has the in-place--=
expected of aBuffer
-- albeit only taking aTraversableOnce[A]
. Is there any hope it can also have an in-placedropRight
? A syntax likemyListBuffer --= n
feels convenient to me (wheren
is the number of elements to drop from the end ofmyListBuffer
).I do already know that there is the possibility of getting the same end-result using
But, that’s an overkill because the temporary collection produced by
myListBuffer.drop(myListBuffer.size - n)
is more than what is required for doing simply an in-placedropRight
. Merelyn
suffices.