根據「Scala編程」一書的第44頁,list
數據結構中存在remove
函數。但是,當我在解釋器中嘗試示例時,我不斷收到錯誤。有誰知道爲什麼?下面是一個示例scala「刪除」不起作用
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)
你能更具體嗎?在棄用filterNot已被命名爲替代和一個測試對我產生了相同的結果。 – drexin 2013-02-19 06:38:06
我的錯誤。我誤解了'-'。 – 2013-02-19 15:11:48