summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorDimitris Kokkonis <kokkonisd@gmail.com>2020-10-10 12:31:09 +0200
committerDimitris Kokkonis <kokkonisd@gmail.com>2020-10-10 12:31:09 +0200
commit916dceba25fcca6d7d9858d25c409bc9984c5fce (patch)
treefb9e604256d3c3267e0f55de39e0fa3b4b0b0728 /scala.html.markdown
parent922fc494bcce6cb53d80a5c2c9c039a480c82c1f (diff)
parent33cd1f57ef49f4ed0817e906b7579fcf33c253a1 (diff)
Merge remote-tracking branch 'upstream/master' into master
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown5
1 files changed, 3 insertions, 2 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index c7a8842e..08fd37e4 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -252,7 +252,7 @@ weirdSum(2, 4) // => 16
// The return keyword exists in Scala, but it only returns from the inner-most
// 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:
+// It has no effect on anonymous functions. For example here you may expect foo(7) should return 17 but it returns 7:
def foo(x: Int): Int = {
val anonFunc: Int => Int = { z =>
if (z > 5)
@@ -260,9 +260,10 @@ def foo(x: Int): Int = {
else
z + 2 // This line is the return value of anonFunc
}
- anonFunc(x) // This line is the return value of foo
+ anonFunc(x) + 10 // This line is the return value of foo
}
+foo(7) // => 7
/////////////////////////////////////////////////
// 3. Flow Control