Created
June 18, 2014 18:21
-
-
Save erikkaplun/d6e6730cd4faa4ee6b82 to your computer and use it in GitHub Desktop.
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
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