diff options
author | Mark Green <mark@antelope.nildram.co.uk> | 2016-01-22 00:54:49 +0000 |
---|---|---|
committer | Mark Green <mark@antelope.nildram.co.uk> | 2016-01-22 00:54:49 +0000 |
commit | 57053bc95d4166a42da8f6d1732dd21a217b073a (patch) | |
tree | 293a7775d4b46313a2ee955691141095653d4044 /scala.html.markdown | |
parent | def04721be506f1c7ff5ddf407f2333999570a89 (diff) | |
parent | 9a5bb286686f5dd4fb743c1bd15ad70a3c6a4a3f (diff) |
Merge remote-tracking branch 'refs/remotes/adambard/master'
Diffstat (limited to 'scala.html.markdown')
-rw-r--r-- | scala.html.markdown | 14 |
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 { |