<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>We should add the full collection of ruby methods <a href="http://matthewcarriere.com/06/23/using-select-reject-collect-inject-and-detect/">http://matthewcarriere.com/06/23/using-select-reject-collect-inject-and-detect/</a></div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"><br>Sent from my iPhone</div><div><br>On 30 Dec 2015, at 02:40, Keith Smiley via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div>+1. We've added an extension for this and find it very useful.<br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 29, 2015 at 18:38 Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<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> </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> -> <span style="color:#703daa">Bool</span>) <span style="color:#bb2ca2">rethrows</span> -> <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>
_______________________________________________<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=xV0JY-2FdZMnUMvSFtZnLiBPRTDDOSQf3-2FpH33HYOlBxG5-2BfRag1YoPimeBEg1K-2Bo5cmHOZQUnouH-2Btp0oGsr851EIOW1QheNTiLhWsdCWZJDY6AAwHR1JsSEH-2Bn5kTSuBMeYkpMzbcSxLAhnANmQiR7AlmtjwKnnGCYgIlHvd4J3JBwgUiZmv5dhNZrEMaR45mQZakX1HIkWAYsjdO36MzOEBw79Pk3qSV5TSHNFkzlE-3D" alt="" width="1" height="1" border="0" style="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></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>