Given this pattern match:
List(1,2,3) match {
case head :: tail => println(">>> head=" + head)
}
I’m assuming that ‘::’ is the case class found in scala.collection.immutable, but how is ‘::’ allowed to be written in that form (infix notation)? – is there a specific rule to allow for that?
Thanks
You can even write:
Basically anything where a pattern is expected (an assignment, a
matchstatement or a line in a for-comprehension) can take an extractor, which is defined as an entity with anunapplymethod.One of the pieces of syntactic sugar that scala provides you with is that; if you have an extractor
X(a, b), this can be written asa X b. Here’s an example with case classes (which have a default extractor):The ability to write such entities infix extends to types as well:
Note that in neither case, does scala restrict such infix operators to symbolic identifiers