Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: why remove 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 deprecated. Being immutable it should be clear that remove would return a new list. In scaladoc you can find only:

Deprecated: use filterNot' instead

like image 689
onof Avatar asked Jun 21 '11 09:06

onof


1 Answers

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.

like image 107
axel22 Avatar answered Nov 13 '22 09:11

axel22