Created
April 11, 2013 16:13
-
-
Save Mortimerp9/5364769 to your computer and use it in GitHub Desktop.
example custom matcher
This file contains 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 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