<div dir="ltr">Is it worth considering a version that returns a tuple of (index, element) ?<div><br></div><div>Nevin</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">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" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+1. We&#39;ve added an extension for this and find it very useful.<br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Tue, Dec 29, 2015 at 18:38 Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><u></u>




<div><div>I&#39;m proposing a new extension method on SequenceType called find(). It&#39;s similar to CollectionType.indexOf() except it returns the element:<br></div>
<div> </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 style="color:#bb2ca2">extension</span><span style="color:#000000"> </span>SequenceType<span style="color:#000000"> {</span></p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(144,45,208)"><span style="color:#000000">    </span>/// Returns the first element where `predicate` returns `true`, or `nil`</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(144,45,208)"><span style="color:#000000">    </span>/// if such value is not found.</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:#bb2ca2">public</span> <span style="color:#bb2ca2">func</span> find(<span style="color:#bb2ca2">@noescape</span> predicate: (<span style="color:#bb2ca2">Self</span>.Generator.Element) <span style="color:#bb2ca2">throws</span> -&gt; <span style="color:#703daa">Bool</span>) <span style="color:#bb2ca2">rethrows</span> -&gt; <span style="color:#703daa">Self</span>.<span style="color:#703daa">Generator</span>.<span style="color:#703daa">Element</span>? {</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:#bb2ca2">for</span> elt <span style="color:#bb2ca2">in</span> <span style="color:#bb2ca2">self</span> {</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">            <span style="color:#bb2ca2">if</span> <span style="color:#bb2ca2">try</span> predicate(elt) {</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">                <span style="color:#bb2ca2">return</span> elt</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">            }</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">        }</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:#bb2ca2">return</span> <span style="color:#bb2ca2">nil</span></p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</p>
<p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo">}<br></p><div> </div>
<div>-Kevin Ballard</div>
</div>
<div> </div>

<img alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></div></div>


_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>
<img alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>