2

I have a function, that has the following definition:

def expectMsgPF[T](max: Duration = Duration.Undefined, hint: String = "")(f: PartialFunction[Any, T]): T = { 

When I call it as follows:

val res1 = listener1.expectMsgPF(1.second) 

Is res1 a function?

I would like to write as follow:

 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) } 

But it does not work.

1
  • 1
    expectMsgPF is a method, not a function. - res1 can be a function, if the expected type is of a function. Commented Jun 9, 2019 at 19:42

1 Answer 1

3

To make res1 { case status: ServerStatus => status.health should be(ServersOffline) } work, try helping the compiler out by providing type parameter T to expectMsgPF[T] like so

val res1 = listener1.expectMsgPF[Assertion](1.second) _ 

This makes res1 indeed a function of the type

PartialFunction[Any, Assertion] => Assertion 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.