Created
September 13, 2018 14:03
-
-
Save busti/9ec99e9a6f260d6beb42034ead05a9b0 to your computer and use it in GitHub Desktop.
Satisfies exhaustiveness for some reason (in scalafiddle, test in scalac later)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.Random | |
// Parent Event definitions | |
sealed trait Event | |
case object Noop extends Event | |
trait TypedEvent[M] extends Event | |
// Some type that is used with events | |
case class Entity(x: Int, y: Int) | |
// Some events that apply to the above | |
case object Foo extends TypedEvent[Entity] | |
case class Bar(i: Int) extends TypedEvent[Entity] | |
// Some random event | |
val ev = Random.shuffle( | |
Seq(Foo, Bar(1), Bar(2)) | |
).head | |
// Trying to match for that exhaustively | |
ev match { | |
case Foo => println("foo") | |
case Bar(1) => println("1") | |
case Bar(2) => println("everything else") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment