Match error for 3 or more Params
windbird123 opened this issue · comments
JaeMyung Kim commented
compile error when 3 or more params
val details = Root / "details" & Param[String]("engine") & Param[String]("device") & Param[String]("query")
val s = "/details?engine=google&device=mobile&query=covid19"
s match {
case details(engine, device, query) =>
println(s"engine=$engine")
println(s"device=$device")
println(s"query=$query")
case _ =>
}
}
Result:
too many patterns for trait Route offering ((String, String), String): expected 2, found 3
case details(engine, device, query) =>
And if I change the code like below
val details = Root / "details" & Param[String]("engine") & Param[String]("device") & Param[String]("query")
val s = "/details?engine=google&device=mobile&query=covid19"
s match {
case details(x, y) =>
println(s"x=$x")
println(s"y=$y")
case _ =>
}
Result:
x=(google,mobile)
y=covid19
Andreas Drobisch commented
the output gives the hint: params are nested as tuples to the left and you need to match them as such:
import trail._
val details = Root / "details" & Param[String]("engine") & Param[String]("device") & Param[String]("query")
val s = "/details?engine=google&device=mobile&query=covid19&fourth=4"
s match {
case details((engine, device), query) =>
println(s"params: $engine, $device, $query")
case _ =>
}
params: google, mobile, covid19
if you would add a fourth:
case details(((engine, device), query), fourth)
JaeMyung Kim commented
@adrobisch thank you.