Skip to content

Instantly share code, notes, and snippets.

@lopopolo
Last active August 29, 2015 14:07
Show Gist options
  • Save lopopolo/74ee69f7fdcc4fe506d9 to your computer and use it in GitHub Desktop.
Save lopopolo/74ee69f7fdcc4fe506d9 to your computer and use it in GitHub Desktop.
Scala return keyword short-circuits code execution in other functions
scala> foo1
finally
res0: String = foo
scala> foo2
finally
after
res1: String = foo
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