Scala: why removal is deprecated in favor of filterNot?

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 out of date. Being immutable, it should be clear that remove will return a new list. In scaladoc you can only find:

Deprecated: use filterNot 'instead

+6
source share
1 answer

This is because the remove method was not coherent - for some collections, it performed modified deletion in place, while for immutable collections, it created a new version. Methods with overhead (volumetric) modifications should be available only for mutable collections.

+14
source

Source: https://habr.com/ru/post/890997/


All Articles