[swift-evolution] For... else

Matthew Johnson matthew at anandabits.com
Mon Jan 25 07:59:03 CST 2016



Sent from my iPad

> On Jan 25, 2016, at 3:41 AM, Howard Lovatt via swift-evolution <swift-evolution at swift.org> wrote:
> 
> It would be easy enough to add:
> 
> func forEach(
>     @noescape elements body: (Element) throws -> Void,
>     @noescape otherwise otherwise: () throws -> Void
> ) rethrows
> 
> to the standard library or write it yourself.

Not unless / until we get the ability for a noescape closure to influence control flow (break, return, etc).  Even then this is clunkier than adding else to the language would be.

> 
>> On 23 Jan 2016, at 12:59 PM, Félix Cloutier via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> I frequently need something like that and I'd like to have it in Swift too.
>> 
>> Félix
>> 
>>> Le 22 janv. 2016 à 13:22:45, Ben Langmuir via swift-evolution <swift-evolution at swift.org> a écrit :
>>> 
>>> Previous discussion here:
>>> https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001110.html
>>> 
>>> 
>>>> On Jan 22, 2016, at 8:22 AM, Lee M via swift-evolution <swift-evolution at swift.org> wrote:
>>>> 
>>>> This has likely been discussed already, but I haven't been able to find it anywhere.
>>>> Example:
>>>> 
>>>>    let items: Int = []
>>>> 
>>>>    for item in items {
>>>>        print(item)
>>>>    }
>>>>    else {
>>>>        print("No items")
>>>>    }
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160125/262822f1/attachment.html>


More information about the swift-evolution mailing list