receiveis a regular partial function in Scala. You can write something like this in your case:
case class Example(number: Int, text: String)
override def receive = {
case message: ClassOne =>
// do something with ClassOne instance
case message: ClassTwo =>
// do something with ClassTwo instance
case Example(n, t) =>
println(t * n)
case Example(n, t) if n > 10 =>
println("special case")
}
You do not need to include a special case for unprocessed messages if your application logic does not require processing of all possible messages.
The first two cases, matching the message type and subtypes, will also match. The latter not only corresponds to the type Example, but also “deconstructs” it by means of comparison with the sample.
source
share