Collect obsolete high-level operations (list: List [A] - a: A)

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 this is because List is not very suitable for this operation in terms of performance, but we still have a length method that should be avoided. What will collection operators look like in future versions of scala?

+5
source share
1 answer

The problem with the method Listis that she never did what you expected from her. 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 you do not receive; instead you get

1,2,3,1,2,3 - 1 == 2,3,2,3

(this is exactly what gives filterNotand which you should expect).

a Set , .

+7

All Articles