kmdent
kmdent

Reputation: 1587

Match statements with conditionals

I want to do something like:

myVar match{
   case 0 => 1
   case (myVar > 9) => 10
   case _ => _
}

Is there a way to do this with match statements in scala?

Upvotes: 2

Views: 177

Answers (1)

missingfaktor
missingfaktor

Reputation: 92016

myVar match {
  case 0 => 1
  case n if n > 9 => 10
  case n => n
}

Upvotes: 9

Related Questions