summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorEv Bogdanov <evbogdanov.com@gmail.com>2018-09-08 21:09:42 +0300
committerEv Bogdanov <evbogdanov.com@gmail.com>2018-09-08 21:09:42 +0300
commit0799909efb0392cf1a2d42e5cad3439449fa9ddc (patch)
tree963a666e664cd3f74adbca6bef593ce66d4c2f5b /scala.html.markdown
parentb622673dae3441f1260401fbb44d90e0e4aea6a2 (diff)
parent49a2bf306fcf365192934d006a244a9033909850 (diff)
Merge remote-tracking branch 'upstream/master' into jquery-ru
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown16
1 files changed, 10 insertions, 6 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index 016e2b4f..7429ac9a 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -253,16 +253,20 @@ weirdSum(2, 4) // => 16
// def that surrounds it.
// WARNING: Using return in Scala is error-prone and should be avoided.
// It has no effect on anonymous functions. For example:
-def foo(x: Int): Int = {
- val anonFunc: Int => Int = { z =>
+def addTenButMaybeTwelve(x: Int): Int = {
+ val anonMaybeAddTwo: Int => Int = { z =>
if (z > 5)
- return z // This line makes z the return value of foo!
+ return z // This line makes z the return value of addTenButMaybeTwelve!
else
- z + 2 // This line is the return value of anonFunc
+ z + 2 // This line is the return value of anonMaybeAddTwo
}
- anonFunc(x) // This line is the return value of foo
+ anonMaybeAddTwo(x) + 10 // This line is the return value of addTenButMaybeTwelve
}
+addTenButMaybeTwelve(2) // Returns 14 as expected: 2 <= 5, adds 12
+addTenButMaybeTwelve(7) // Returns 7: 7 > 5, return value set to z, so
+ // last line doesn't get called and 10 is not added
+
/////////////////////////////////////////////////
// 3. Flow Control
@@ -716,7 +720,7 @@ 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
+// Your programs entry point is defined in a scala file using an object, with a
// single method, main:
object Application {
def main(args: Array[String]): Unit = {