summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorGeorge Petrov <petrovg@gmail.com>2013-07-29 15:18:24 +0100
committerGeorge Petrov <petrovg@gmail.com>2013-07-29 15:18:24 +0100
commit99b16c2672a2fc0b1dbb063c0b6e066158922099 (patch)
treee48c8c0fd9ded4ffefe76a684f9b550d02d53cea /scala.html.markdown
parentd346342ad608849bdd1bcae7973bbff571225ba1 (diff)
Now really adding some pattern matching
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown19
1 files changed, 19 insertions, 0 deletions
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