Skip to content

Instantly share code, notes, and snippets.

@erikkaplun
Created June 18, 2014 18:21
Show Gist options
  • Save erikkaplun/d6e6730cd4faa4ee6b82 to your computer and use it in GitHub Desktop.
Save erikkaplun/d6e6730cd4faa4ee6b82 to your computer and use it in GitHub Desktop.
trait Extractor[T, U] { def unapply(x: T): Option[U] }
object Extractor {
def apply[T, U](f: PartialFunction[T, U]) = new Extractor[T, U] {
def unapply(x: T) = f.lift(x)
}
}
val EmployedAt = Extractor[Person, Company] {
case Person(_, _, Some(Position(_, Some(c)))) => c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment