How Scala reads events

Good morning,

I am trying to see, how does Scala pattern match what type of Actor Event is happening, for example whether the event is a send event, receive event, function call event, etc.

Is it possible to have a form of match statement trying to check whether Scala matches a send event, … i.e. Is it possible to write something like this :

act match {
case (A ! a) => print “send event read”
case ( A receive message) => print " receive event read"
case (function_name(params)) => print “function call read”
case _ => “No event read”

Thanks a lot and good day :slight_smile:

match is a language construct that matches some value

12 match {
  case 1 => "it's 1"
  case 2 => "it's 2"
  case 12 => "it's 12"
  case _ => "it's a lot!"

is translated to

if (12 == 1) "it's 1"
else if (12 == 2) "it's 2"
else if (12 ==12) "it's 12"
else "it's a lot"

There are no actors or events involved.

I don’t quite understand what you want the translated code to look like, so I can’t tell you how to write a match that does that.


When you’re talking about events and Actors, you’re probably talking about Akka (which is not the main interest of this forum, but hey).

When using Akka (and even more so when using typed Actors), you define the types of messages an Actor reacts on usually as a sealed class hierarchy. You seem to want react on anything being thrown at an Actor, which is not what is done usually.

Please try asking specific questions and to describe the problem you’re trying to solve; rather than half-heartedly throwing something together nobody can really make sense of.