Created
January 20, 2015 15:13
-
-
Save eloraburns/ee89b94f8602e25296d3 to your computer and use it in GitHub Desktop.
Scoping of "return" in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> // "return" binds to the nearest method, not function literals. | |
scala> def myfun() { | |
| val foo = List(1, 2, 3); | |
| val bar = foo map { x => | |
| println(x) | |
| if (x == 2) return | |
| } | |
| println("Dead code") | |
| } | |
myfun: ()Unit | |
scala> myfun | |
1 | |
2 | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment