diff options
author | Max Schumacher <maximilianbschumacher@gmail.com> | 2020-07-07 15:30:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 15:30:16 +0200 |
commit | 7deddde5a0dc6a0fb4e1127ecd3e3ac9a64f0b53 (patch) | |
tree | 53d3875b69f9fd12d65f23043b782091d57a14fe | |
parent | dcb6c9c065840178815ff2420f055df167cf4fec (diff) | |
parent | f69c039f1c8e4ef78b49b6ec3a8e5bbd0b4ba8d1 (diff) |
Merge pull request #3942 from panaali/patch-2
[scala/en] - clarify `return` keyword usage
-rw-r--r-- | scala.html.markdown | 5 |
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 |