Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala "remove" not working

Tags:

scala

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

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)
like image 576
learner Avatar asked Dec 09 '22 17:12

learner


1 Answers

List had a remove method in earlier versions, but it has been deprecated in 2.8 and removed in 2.9. Use filterNot instead.

like image 58
drexin Avatar answered Dec 29 '22 11:12

drexin