这是我正在尝试执行的代码,
type Set = scala.collection.immutable.Set[Int]
定义的类型别名Set
def filter(s: Set, p: Int => Boolean): Set = Set(1,2,3)
filter:(s:Set,p:Int => Boolean)设置
filter(Set(1,2,3), (4 => 2 < 3))
错误:不是合法的形式参数 过滤器(Set(3,4),(4 =&gt; 2&lt; 3))
我做错了什么?请帮忙。
答案 0 :(得分:2)
你的语法既不是谓词,也不是值,你不能将lambda参数命名为'4',你不能将4传递给boolean。正确的语法可能是:
filter(Set(1,2,3), the4 => (2 < 2))
或者也许:
filter(Set(1,2,3), x => (x < 2))