Why are non-local returns not allowed in lambdas? ...
# announcements
f
Why are non-local returns not allowed in lambdas? I can't find an explanation about the "why" anywhere
m
They are for inlined lambdas. Do you have a concrete example?
f
But why not for non-inlined lambdas?
m
It has no access to the outer function. It may be called somewhere completely differently. Or even multiple times. Or from another Thread, long after the function that created the lambda has already returned.
f
f
ok, thank you both
@FunkyMuse I kinda understand crossinline, I'm just not sure why non-local returns are not allowed in lambdas in the first place
but @Marc Knaup’s example make sense
m
@Florian can you bring up an example where you would expect a non-local return to work? Then let’s see why it may not be possible 🙂
f
I can't really come up with an example
I guess it doesn't make any sense
o
My guess is that they want lambdas to act more like FP. Having multiple return statements in a function can be considered (like GOTO statements) a thing of imperative programming.
A regular lambda can be read like an expression. Having return statements in your code would block thay
f
thank you everyone