[swift-evolution] else clause for loops like that in Python
Donnacha Oisín Kidney
oisin.kidney at gmail.com
Tue Dec 8 19:25:42 CST 2015
Although I see now that it doesn’t for arrays. ¯\_(ツ)_/¯
> On 9 Dec 2015, at 01:21, Donnacha Oisín Kidney <oisin.kidney at gmail.com> wrote:
> Be careful with lazy.filter.first! It evaluates the whole sequence, usually.
>> On 9 Dec 2015, at 01:13, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>>> What about searching for something in an array? The not found code would go in the nobreak clause.
>> For an array, I would almost always use `if let` with `lazy.filter.first` or `indexOf`. The if branch is “found”, else is “not found”.
>> If that wasn’t suitable for some reason, I’d probably put the search loop like that in its own function or method and return early from inside the loop. If you reach the code after the loop, the search has failed.
>> I’m not saying it’s a useless feature, just that *I* can’t imagine using it.
>> Brent Royal-Gordon
>> swift-evolution mailing list
>> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution