我正在尝试创建一个函数,其返回类型不仅仅是一个函数(A=>B
),而是相同的函数。这是一个例子:
trait Command
type Config = Command => Command
def addCommand(c: Command): Config = {
addCommand _
}
以上似乎没问题,但它给出了这个编译错误:
found : Command => Command
required: Command
有没有办法修理这件事?
答案 0 :(得分:1)
干嘛怎么样?
scala> val ac: Command => Config = cm => confCom => confCom
ac: Command => (Command => Command) = <function1>
scala> val c: Config = ac(new Command {})
c: Command => Command = <function1>