<div>Why not add to the library:</div><div><br></div><div><div>extension Sequence {</div><div> func forEach(_ eacher: (Iterator.Element) throws -> Void, elser: () throws -> Void) rethrows {</div><div> var hasIterated = false</div><div> for element in self {</div><div> hasIterated = true</div><div> try eacher(element)</div><div> }</div><div> guard hasIterated else {</div><div> try elser()</div><div> return</div><div> }</div><div> }</div><div>}</div><div><br></div><div class="gmail_quote"><div>On Fri, 3 Feb 2017 at 8:33 pm, Jeremy Pereira via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="gmail_msg">
> On 2 Feb 2017, at 20:12, Erica Sadun via swift-users <<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> I've taken this over to Swift Users from Swift Evolution.<br class="gmail_msg">
><br class="gmail_msg">
> I think you'd want to handle the exceptional case first,<br class="gmail_msg">
<br class="gmail_msg">
Although it is the way I would do it for an array, sometimes you don’t know that a sequence is empty until after you have iterated it.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
swift-users mailing list<br class="gmail_msg">
<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="gmail_msg">
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature">-- Howard.</div>