When a function value containing a return statement is evaluated nonlocally, [...]
Answer
the computation is dropped and the result is returned by throwing a NonLocalReturnControl[A].
Tags
#scala
Question
When a function value containing a return statement is evaluated nonlocally, [...]
Answer
?
Tags
#scala
Question
When a function value containing a return statement is evaluated nonlocally, [...]
Answer
the computation is dropped and the result is returned by throwing a NonLocalReturnControl[A].
If you want to change selection, open original toplevel document below and click on "Move attachment"
Parent (intermediate) annotation
Open it When a function value containing a return statement is evaluated nonlocally, the computation is abandoned and the result is returned by throwing a NonLocalReturnControl[A].
Original toplevel document
tpolecat it returns from the method it appears in. Another example:
def foo: Int = {
val sumR: List[Int] => Int = _.foldLeft(0)((n, m) => return n + m)
sumR(List(1,2,3)) + sumR(List(4,5,6))
}
scala> foo
res4: Int = 1
Non-Local Return
<span>When a function value containing a return statement is evaluated nonlocally, the computation is abandoned and the result is returned by throwing a NonLocalReturnControl[A]. This implementation detail escapes into the wild without much ceremony:
def lazily(s: => String): String =
try s catch { case t: Throwable => t.toString }
def foo: String = laz
Summary
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Details
No repetitions
Discussion
Do you want to join discussion? Click here to log in or create user.