无法应用参数化柯里化函数
Unable to apply parameterised curried function
我有一个函数,其定义如下:
def expectMsgPF[T](max: Duration = Duration.Undefined, hint: String = "")(f: PartialFunction[Any, T]): T = {
当我这样调用时:
val res1 = listener1.expectMsgPF(1.second)
res1
是函数吗?
我想这样写:
val res1 = listener1.expectMsgPF(1.second) _
val res2 = listener2.expectMsgPF(1.second)
Then("it should contain `Kafka and SAP are offline`")
res1 {
case status: ServerStatus =>
status.health should be(ServersOffline)
}
但是不行。
要使 res1 { case status: ServerStatus => status.health should be(ServersOffline) }
工作,请尝试通过向 expectMsgPF[T]
提供类型参数 T
来帮助编译器,就像这样
val res1 = listener1.expectMsgPF[Assertion](1.second) _
这使得 res1
确实是
类型的函数
PartialFunction[Any, Assertion] => Assertion
我有一个函数,其定义如下:
def expectMsgPF[T](max: Duration = Duration.Undefined, hint: String = "")(f: PartialFunction[Any, T]): T = {
当我这样调用时:
val res1 = listener1.expectMsgPF(1.second)
res1
是函数吗?
我想这样写:
val res1 = listener1.expectMsgPF(1.second) _
val res2 = listener2.expectMsgPF(1.second)
Then("it should contain `Kafka and SAP are offline`")
res1 {
case status: ServerStatus =>
status.health should be(ServersOffline)
}
但是不行。
要使 res1 { case status: ServerStatus => status.health should be(ServersOffline) }
工作,请尝试通过向 expectMsgPF[T]
提供类型参数 T
来帮助编译器,就像这样
val res1 = listener1.expectMsgPF[Assertion](1.second) _
这使得 res1
确实是
PartialFunction[Any, Assertion] => Assertion