<div dir="ltr">+1 we also have a very similar extension.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 30, 2015 at 1: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 src="https://u2002410.ct.sendgrid.net/wf/open?upn=SZEgwDQgUrfMl3FalbD3sS2ih79f5jEyc67OkyJWPWkMqUbHtNT8qufjew1uLw-2FuDSPw8vmswg2ipW8wlflywoamaIqIWsVAEN5JyP-2FXQTGu031MZbaGfRLa2HEahWNnwepKXJH7m-2BUcGbBbTkPasZS5N2HspREiIxRioQH0csc-2FOM4x-2FjKq7bd4juIe6Qos5IJ6Qk51ZIZYlecbJQUj-2F-2F8DWMkbznaIKnpadzFcrOo-3D" 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 src="https://u2002410.ct.sendgrid.net/wf/open?upn=pQw7h83fWt3LLbgkfL4TSUL0weaZnVFZxDe5GShw4uQCoB1cq6iZDVrdasTbdFRI-2BLQD-2FCTuUJs1-2BkmsA4iX28z1-2B9972l-2F0WeuULr6WmgkcmqbNOYjyAzt0pgvGSL-2FB7YwBcAs1EWDx5ra5qgG4GcMO7VBG1d2s7NiE6thBVgfQInmFbiAF950MBuRXo8pIHUnBIrWGemtYqyrMy1rVSRmJNfq9AeOME1p8OgPIa6w-3D" 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>