Skip to content

Instantly share code, notes, and snippets.

@busti
Created September 13, 2018 14:03
Show Gist options
  • Save busti/9ec99e9a6f260d6beb42034ead05a9b0 to your computer and use it in GitHub Desktop.
Save busti/9ec99e9a6f260d6beb42034ead05a9b0 to your computer and use it in GitHub Desktop.
Satisfies exhaustiveness for some reason (in scalafiddle, test in scalac later)
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