Now really adding some pattern matching

This commit is contained in:
George Petrov 2013-07-29 15:18:24 +01:00
parent d346342ad6
commit 99b16c2672

View File

@ -135,10 +135,29 @@ Person("George", "1234") == Person("Kate", "1236")
// Pattern matching
val me = Person("George", "1234")
me match { case Person(name, number) => "We matched someone : " + name + ", phone : " + number }
me match { case Person(name, number) => "Match : " + name; case _ => "Hm..." }
me match { case Person("George", number) => "Match"; case _ => "Hm..." }
me match { case Person("Kate", number) => "Match"; case _ => "Hm..." }
me match { case Person("Kate", _) => "Girl"; case Person("George", _) => "Boy" }
val kate = Person("Kate", "1234")
kate match { case Person("Kate", _) => "Girl"; case Person("George", _) => "Boy" }
// Regular expressions
// Strings