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)
List
had a remove method in earlier versions, but it has been deprecated in 2.8 and removed in 2.9. Use filterNot
instead.
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