Skip to content

Instantly share code, notes, and snippets.

@jducoeur
Created October 14, 2016 18:57
Show Gist options
  • Save jducoeur/5e99bbd06f16297e205112c261604e89 to your computer and use it in GitHub Desktop.
Save jducoeur/5e99bbd06f16297e205112c261604e89 to your computer and use it in GitHub Desktop.
sealed trait MyTrait
case class Impl1() extends MyTrait
case class Impl2() extends MyTrait
def recover1:PartialFunction[Any, Unit] = {
case s:String => println("It was a String")
case i:Int => println("It was an Int")
}
def recoverMyTrait:PartialFunction[MyTrait, Unit] = {
case Impl1() => println("Got an Impl1")
case Impl2() => println("Got an Impl2")
}
def recover:PartialFunction[Any, Unit] =
recover1 orElse recoverMyTrait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment