summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorAdam <adam@adambard.com>2016-01-08 14:35:53 +0800
committerAdam <adam@adambard.com>2016-01-08 14:35:53 +0800
commitef28fa69775ba064dfed212e034b5caae7edb7b9 (patch)
treed3a30be274822754414b438fe9b9c102edc09630 /scala.html.markdown
parent8ad537a9ba9889234a63c5a38caeab3e225856e4 (diff)
parent04166190367a93236e7173901dff7ae9661736ba (diff)
Merge branch 'master' of github.com:adambard/learnxinyminutes-docs
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown14
1 files changed, 13 insertions, 1 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index bc8cd422..c2aa942c 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
@@ -612,6 +621,9 @@ import scala.collection.immutable.{List => ImmutableList}
// Import all classes, except some. The following excludes Map and Set:
import scala.collection.immutable.{Map => _, Set => _, _}
+// Java classes can also be imported. Scala syntax can be used
+import java.swing.{JFrame, JWindow}
+
// Your programs entry point is defined in an scala file using an object, with a
// single method, main:
object Application {