<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Good thought, but I doubt such a method would pull its own weight.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard<br></div>
<div>&nbsp;</div>
<div>On Wed, Dec 30, 2015, at 04:24 PM, Nevin Brackett-Rozinsky wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>Is it worth considering a version that returns a tuple of (index, element) ?<br></div>
<div>&nbsp;</div>
<div>Nevin<br></div>
<div>&nbsp;</div>
</div>
<div><div>&nbsp;</div>
<div><div>On Tue, Dec 29, 2015 at 9:40 PM, Keith Smiley via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style:solid;padding-left:1ex;"><div>+1. We've added an extension for this and find it very useful.<br></div>
<div><div><div><div dir="ltr">On Tue, Dec 29, 2015 at 18:38 Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div>
</div>
</div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style:solid;padding-left:1ex;"><div><div><div><u></u><br></div>
<div><div>I'm proposing a new extension method on SequenceType called find(). It's similar to CollectionType.indexOf() except it returns the element:<br></div>
<div>&nbsp;</div>
<div><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112, 61, 170);"><span class="colour" style="color:rgb(187, 44, 162)">extension</span><span class="colour" style="color:rgb(0, 0, 0)"></span>SequenceType<span class="colour" style="color:rgb(0, 0, 0)"> {</span><br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(144, 45, 208);"><span class="colour" style="color:rgb(0, 0, 0)"></span>/// Returns the first element where `predicate` returns `true`, or `nil`<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(144, 45, 208);"><span class="colour" style="color:rgb(0, 0, 0)"></span>/// if such value is not found.<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span class="colour" style="color:rgb(187, 44, 162)">public</span> <span class="colour" style="color:rgb(187, 44, 162)">func</span> find(<span class="colour" style="color:rgb(187, 44, 162)">@noescape</span> predicate: (<span class="colour" style="color:rgb(187, 44, 162)">Self</span>.Generator.Element) <span class="colour" style="color:rgb(187, 44, 162)">throws</span> -&gt; <span class="colour" style="color:rgb(112, 61, 170)">Bool</span>) <span class="colour" style="color:rgb(187, 44, 162)">rethrows</span> -&gt; <span class="colour" style="color:rgb(112, 61, 170)">Self</span>.<span class="colour" style="color:rgb(112, 61, 170)">Generator</span>.<span class="colour" style="color:rgb(112, 61, 170)">Element</span>? {<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span class="colour" style="color:rgb(187, 44, 162)">for</span> elt <span class="colour" style="color:rgb(187, 44, 162)">in</span> <span class="colour" style="color:rgb(187, 44, 162)">self</span> {<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span class="colour" style="color:rgb(187, 44, 162)">if</span> <span class="colour" style="color:rgb(187, 44, 162)">try</span> predicate(elt) {<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span class="colour" style="color:rgb(187, 44, 162)">return</span> elt<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span class="colour" style="color:rgb(187, 44, 162)">return</span> <span class="colour" style="color:rgb(187, 44, 162)">nil</span><br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;">&nbsp; &nbsp; }<br></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;">}<br></p><div>&nbsp;</div>
<div>-Kevin Ballard<br></div>
</div>
<div>&nbsp;</div>
<div><img style="min-height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt=""><br></div>
</div>
</div>
</div>
<div>_______________________________________________<br></div>
<div>
swift-evolution mailing list<br></div>
<div> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote></div>
<div><img style="min-height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt=""> <br></div>
<div>_______________________________________________<br></div>
<div>
swift-evolution mailing list<br></div>
<div> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
<div>&nbsp;</div>
</blockquote></div>
</div>
</blockquote></body>
</html>