[swift-evolution] Remove forEach?

Matthew Johnson matthew at anandabits.com
Wed Dec 9 11:43:51 CST 2015


>>>>> Another direction you might take this is to make it a type annotation on the function type, like throws, so forEach has a type like this:
>>>>> 
>>>>> func forEach(body: (Element) breaks -> ())
>>>>> 
>>>>> and a closure that `breaks` has nonlocal behavior for break/continue/return (and is implied to be noescape and void-returning, I guess).

I missed this post the first time around.  Is a really great idea and is something I hoped we might get eventually.  It allows "control flow" functions to behave as expected.

I assume a caller could pass a non-breaking closure if desired just as we can pass a non-throwing closure if desired, right?
,
How would break and continue interact with the caller of the closure?  It would need to implement the correct behavior of skipping to the next loop cycle or moving on to any post-loop logic.

How would this behave for a closure that is stored and called later, possibly asynchronously?  Or would it only be allowed on closures declared

Matthew


More information about the swift-evolution mailing list