summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorven <vendethiel@hotmail.fr>2018-09-08 23:29:35 +0200
committerGitHub <noreply@github.com>2018-09-08 23:29:35 +0200
commit6d087ae0f289e7013807639cbd609f991f968166 (patch)
tree909eebc77b92a360acc16a7e8740a0b9122f8aca /scala.html.markdown
parent49a2bf306fcf365192934d006a244a9033909850 (diff)
Revert "[scala/en] Make return value example actually demonstrate issue" (#3213)
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown14
1 files changed, 5 insertions, 9 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index 7429ac9a..28424684 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -253,20 +253,16 @@ 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 addTenButMaybeTwelve(x: Int): Int = {
- val anonMaybeAddTwo: Int => Int = { z =>
+def foo(x: Int): Int = {
+ val anonFunc: Int => Int = { z =>
if (z > 5)
- return z // This line makes z the return value of addTenButMaybeTwelve!
+ return z // This line makes z the return value of foo!
else
- z + 2 // This line is the return value of anonMaybeAddTwo
+ z + 2 // This line is the return value of anonFunc
}
- anonMaybeAddTwo(x) + 10 // This line is the return value of addTenButMaybeTwelve
+ anonFunc(x) // This line is the return value of foo
}
-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