I need to use bunch of match case in scala, how do I use for or if inside the match case, so for example:
import scala.util.Random
val x = Random.nextInt(30)
val result = match x {
case 0 to 10 => bad
case 11 to 20 => average
case 20 to 30 => cool
}
first question is how do I do that instead of using floor
, ceil
, round
or other math stuff?
secondly, for string value, in php we could easily use if (x == 'some')||(x == 'thing'){result}
but how this could worked in scala match case?
for example when val x is random A to I:
val result = match x {
case A || B || C => bad
case D || E || F => average
case G || H || I => cool
}
Thanks!