Open yhara opened 3 years ago
On the other hand, I feel like the return
below escapes from fn
, not self.foo
. Maybe return
should behave differently in a fn
and a block (like Ruby's lambda and proc.)
class A
def self.foo
f = fn{
[1,2,3].each do |i: Int|
p i
return if i %2 == 0
end
}
3.times{|i: Int| f.call}
end
end
This is possible but not easy (needs something like exception handlling)
Another possibility is to use CPS(Continuation Passing Style).
eg.