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中工作