How to auto enumerate cases when writing pattern match?
Followed by 4 people
For example, I have follow list of case class definitions.
trait A
case class B extends A
case class C extends A
case class D extends A
When I write pattern match on A,
def foo(x: A) = x match {
case B => ???
case C => ???
case D => ???
}
Is there any way to auto fill those case statements "case B, C, D"??? I remember it is possible when develop in Java to handle enumerations.
Btw, I am running Intellij 12 on Mac.
Please sign in to leave a comment.
It's good idea. Thank you! I created the issue: http://youtrack.jetbrains.com/issue/SCL-6550
Best regards,
Alexander Podkhalyuzin.
The issue state is still 'open'...
And it's probably going to stay that way... Jetbrains is more interested in Kotlin than Scala these days :-(
Hi @Fernado Jimenez,
They actually implemented this a few years ago. You can find out how to use it here:
https://www.jetbrains.com/help/idea/edit-scala-code.html#ce0afed0
Basically if you pick "case (exhaustive)", it will enumerate all cases automatically for you.