From 99b16c2672a2fc0b1dbb063c0b6e066158922099 Mon Sep 17 00:00:00 2001 From: George Petrov Date: Mon, 29 Jul 2013 15:18:24 +0100 Subject: Now really adding some pattern matching --- scala.html.markdown | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'scala.html.markdown') diff --git a/scala.html.markdown b/scala.html.markdown index d6524a8f..d0187667 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -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 -- cgit v1.2.3