val-6ren">
gpt4 book ai didi

scala "remove"不工作

转载 作者:行者123 更新时间:2023-12-04 22:05:58 25 4
gpt4 key购买 nike

根据“Scala 编程”一书的第 44 页,存在用于 remove 数据结构的 list 函数。但是,当我在解释器中尝试该示例时,我不断收到错误消息。有谁知道为什么?这是一个示例

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 在早期版本中有一个 remove 方法,但它在 2.8 中已被弃用并在 2.9 中删除。请改用 filterNot

关于scala "remove"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14947273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com