Skip to content

Instantly share code, notes, and snippets.

@Mortimerp9
Created April 11, 2013 16:13
Show Gist options
  • Save Mortimerp9/5364769 to your computer and use it in GitHub Desktop.
Save Mortimerp9/5364769 to your computer and use it in GitHub Desktop.
example custom matcher
trait ID
case class SequentialID(id: Int) extends ID
case class OtherID(id: Int) extends ID
case class User(val id: ID, val b: Int, val c: Int)
object UserId {
def unapply(w: User) = w match {
case u @ User(SequentialID(id), _, _) => Some(u, id)
case _ => None
}
}
val u = User(SequentialID(1),2,3)
val y = User(OtherID(1),2,3)
u match {
case UserId(u, id) => id
}
y match {
case UserId(u, id) => u
case _ => y
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment