Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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 函数组合导致方法1缺少参数列表_Scala_Functional Programming_Composition - Fatal编程技术网

Scala 函数组合导致方法1缺少参数列表

Scala 函数组合导致方法1缺少参数列表,scala,functional-programming,composition,Scala,Functional Programming,Composition,假设我们有以下功能: def first(a: A): B = ??? def second(b: B): C = ??? 我想使用和组合它们,但使用以下代码: (first andThen second)(a) 结果: <console>:14: error: missing argument list for method first Unapplied methods are only converted to functions when a function type

假设我们有以下功能:

def first(a: A): B = ???
def second(b: B): C = ???
我想使用
组合它们,但使用以下代码:

(first andThen second)(a)
结果:

<console>:14: error: missing argument list for method first
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `first _` or `first(_)` instead of `first`.                                                                                                                                                                    
(first andThen second) (1)
:14:错误:第一个方法缺少参数列表
未应用的方法仅在需要函数类型时才会转换为函数。
您可以通过编写“first”或“first()`而不是“first”来明确此转换。
(第一和第二)(1)
和then()
函数上的一种方法。正如您所定义的,
first()
是一个方法(
def
),而不是一个函数。那些是

你可以把它定义为一个函数

val first : A => B = (a:A) => ???
。。。或者您可以使用将其提升为功能状态

(first _ andThen second)
据说Scala 3将提供一个更透明的eta扩展机制,这样方法和函数之间的区别就不会那么麻烦。

,然后()
是一个
函数上的方法。正如您所定义的,
first()
是一个方法(
def
),而不是一个函数。那些是

你可以把它定义为一个函数

val first : A => B = (a:A) => ???
。。。或者您可以使用将其提升为功能状态

(first _ andThen second)
据说Scala 3将提供更透明的eta扩展机制,这样方法和函数之间的区别就不会那么麻烦。

的确
(第一和第二)
在dotty中工作确实
(第一和第二)
在dotty中工作