Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala:当试图调用以谓词作为其参数之一的函数时,它不是合法的形式参数_Scala - Fatal编程技术网

Scala:当试图调用以谓词作为其参数之一的函数时,它不是合法的形式参数

Scala:当试图调用以谓词作为其参数之一的函数时,它不是合法的形式参数,scala,Scala,这是我试图执行的代码 type Set=scala.collection.immutable.Set[Int] 定义的类型别名集 def过滤器(s:Set,p:Int=>Boolean):Set=Set(1,2,3) 过滤器:(s:Set,p:Int=>Boolean)集 filter(设置(1,2,3),(4=>22您的语法既不是谓词,也不是值,您不能将lambda参数命名为“4”,也不能将4传递为布尔值。正确的语法可能是: filter(Set(1,2,3), the4 => (2 &

这是我试图执行的代码

type Set=scala.collection.immutable.Set[Int]

定义的类型别名集

def过滤器(s:Set,p:Int=>Boolean):Set=Set(1,2,3)

过滤器:(s:Set,p:Int=>Boolean)集

filter(设置(1,2,3),(4=>2<3))

错误:不是合法的形式参数
filter(Set(3,4),(4=>2您的语法既不是谓词,也不是值,您不能将lambda参数命名为“4”,也不能将4传递为布尔值。正确的语法可能是:

filter(Set(1,2,3), the4 => (2 < 2))
过滤器(设置(1,2,3),4=>(2<2))
或许:

filter(Set(1,2,3), x => (x < 2))
过滤器(集合(1,2,3),x=>(x<2))

正如
filter(Set(1,2,3)、(x=>x<3))
中不应该有一个像
x
这样的参数名吗?提示:
filter(Set(1,2,3),the4=>(2<2))
它起作用了FrankPI..ah明白了。它像f(x)=x<3。对吗?谢谢。请写下来作为回答。@Pedrofura你是指
filter(Set(1,2,3),`4=>(2