Scala "delete" does not work

According to page 44 of Scala's Programming book, there is a remove function for the list data structure. However, when I try to give an example in my interpreter, I keep getting errors. Does anyone know why? Here is an example

 scala> val x = List(1,2,3,4,5,6,7,8,9) x: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9) scala> x.remove(_ < 5) <console>:9: error: value remove is not a member of List[Int] x.remove(_ < 5) ^ scala> x.remove(s => s == 5) <console>:9: error: value remove is not a member of List[Int] x.remove(s => s == 5) ^ scala> val y = List("apple","Oranges","pine","sol") y: List[String] = List(apple, Oranges, pine, sol) scala> y.remove(s => s.length ==4) <console>:9: error: value remove is not a member of List[String] y.remove(s => s.length ==4) 
+4
source share
2 answers

List had a delete method in earlier versions, but it was deprecated in 2.8 and removed in 2.9. Use filterNot .

+9
source

ListBuffer has a delete method, but not a List . See here for information on how to idiomatically remove from an immutable list (obviously creating a new list!)

+4
source

All Articles