Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection high-level operation deprecation (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 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?

like image 753
yura Avatar asked Feb 23 '12 00:02

yura


1 Answers

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.

like image 115
Rex Kerr Avatar answered Sep 30 '22 09:09

Rex Kerr