diff options
Diffstat (limited to 'scala.html.markdown')
-rw-r--r-- | scala.html.markdown | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/scala.html.markdown b/scala.html.markdown index bc8cd422..a82983a5 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -327,9 +327,15 @@ divideInts(10, 3) // (Int, Int) = (3,1) val d = divideInts(10, 3) // (Int, Int) = (3,1) d._1 // Int = 3 - d._2 // Int = 1 +// Alternatively you can do multiple-variable assignment to tuple, which is more +// convenient and readable in many cases +val (div, mod) = divideInts(10, 3) + +div // Int = 3 +mod // Int = 1 + ///////////////////////////////////////////////// // 5. Object Oriented Programming @@ -460,6 +466,9 @@ def matchEverything(obj: Any): String = obj match { // You can nest patterns: case List(List((1, 2, "YAY"))) => "Got a list of list of tuple" + + // Match any case (default) if all previous haven't matched + case _ => "Got unknown object" } // In fact, you can pattern match any object with an "unapply" method. This |