Created
January 7, 2012 22:35
-
-
Save diegopacheco/1576302 to your computer and use it in GitHub Desktop.
Scala Pattern Matcher Advanced
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 Color | |
| case class Red(saturation: Int) extends Color | |
| case class Green(saturation: Int) extends Color | |
| case class Blue(saturation: Int) extends Color | |
| def matcher(arg:Any): String = arg match { | |
| case "Chowder" => "Make with clams" | |
| case x: Int => "An Int with value " + x | |
| case Red(100) => "Red sat 100" | |
| case Green(s) => "Green sat " + s | |
| case c: Color => "Some Color: " + c | |
| case w: Any => "Whatever: " + w | |
| case _ => "Default, but Any captures all" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment