pathTokens match {
case List("post") => ("post", "index")
case List("search") => ("search", "index")
case List() => ("home", "index")
} match {
case (controller, action) => loadController(http, controller, action)
case _ => null
}
I wanted contiguous match. but got compile error. 🙁
(pathTokens match {
case List("post") => ("post", "index")
case List("search") => ("search", "index")
case List() => ("home", "index")
}) match {
case (controller, action) => loadController(http, controller, action)
case _ => null
}
When I wrapped first match with parenparenthesis, it worked ok.
Why I need parenthesis here ?
Unfortunately, that’s how the Scala syntax is defined. Please have a look at the specification:
http://www.scala-lang.org/docu/files/ScalaReference.pdf
There you will find the following definition (p. 153, shortened for clarity):
Expr1 ::= PostfixExpr 'match' '{' CaseClauses '}'If you dig into
PostfixExpryou will eventually findSimpleExpr1which contains the following definition:SimpleExpr1 ::= '(' [Exprs [',']] ')' Exprs ::= Expr {',' Expr}That means that
SimpleExpr1(and thusPostfixExpr) can only contain other expressions (like ‘x match y’) when they are wrapped in parentheses.