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 PostfixExpr
you will eventually find SimpleExpr1
which contains the following definition:
SimpleExpr1 ::= '(' [Exprs [',']] ')' Exprs ::= Expr {',' Expr}
That means that SimpleExpr1
(and thus PostfixExpr
) can only contain other expressions (like 'x match y') when they are wrapped in parentheses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With