Why do we have this operator-method
@deprecated("use `filterNot (_ == x)` instead", "2.8.0")
def - [B >: A](x: B): List[B]
//i.e. List(1,23,3,4,5) - 23
deprecated for lists, but not for sets?
Set(1,23,3,4) - 23
If it because List is not very suitable for this operation in terms of performance, but we still have length method we should avoid. How collection operators will look like in future versions of scala?
The problem with the List
method is that it never did what you would expect it to do. Naively, I would expect
1,2,3,1,2,3 - 1,2,3,1 == 2,3
and therefore
1,2,3,1,2,3 - 1 == 2,3,1,2,3
Except that's not what you get; instead you get
1,2,3,1,2,3 - 1 == 2,3,2,3
(which is exactly what filterNot
gives, and which you should expect).
Since elements of a Set
are unique, there is no distinction between the two methods.
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