Last active
August 29, 2015 14:07
-
-
Save lopopolo/74ee69f7fdcc4fe506d9 to your computer and use it in GitHub Desktop.
Scala return keyword short-circuits code execution in other functions
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> foo1 | |
finally | |
res0: String = foo | |
scala> foo2 | |
finally | |
after | |
res1: String = foo |
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
def using[A](f: => A): A = { | |
val r = try f finally println("finally") | |
println("after") | |
r | |
} | |
def foo1: String = using[String](return "foo") | |
def foo2: String = using("foo") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment