Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is this case class match pattern working?

I've just seen this case class in the Scala actors package:

case class ! [a](ch: Channel[a], msg: a)

And in the JavaDoc it describes usage in the following form:

receive {
  case Chan1 ! msg1 => ...
  case Chan2 ! msg2 => ...
}

Why is this not:

receive {
  case !(Chan1, msg1) => ...
  case !(Chan2, msg2) => ...
}

Is the bang operator ! a special case in a similar way to methods ending in a colon :

like image 741
oxbow_lakes Avatar asked Jun 29 '09 16:06

oxbow_lakes


1 Answers

When doing pattern matching, the Scala compiler will interpret o1 c1 o2 the same as c1(o1, o2). That's why :: works inside pattern matches too.

like image 142
Daniel C. Sobral Avatar answered Sep 30 '22 01:09

Daniel C. Sobral