scala> List(1, 2, 3) remove (_ < 2)
<console>:8: warning: method remove in class List is deprecated: use `filterNot'
instead
List(1, 2, 3) remove (_ < 2)
^
res0: List[Int] = List(2, 3)
I don't understand why this is deprecated. Being immutable it should be clear that remove
would return a new list. In scaladoc you can find only:
Deprecated: use filterNot' instead
It's because the method remove
wasn't coherent - for some collections it did a mutable in-place removal, whereas for immutable collections it created a new version. Methods with in-place (bulk) modifications should only be available for mutable collections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With