<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><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 style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span>SequenceType<span style="font-variant-ligatures: no-common-ligatures; 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="font-variant-ligatures: no-common-ligatures; color: #000000">&nbsp; &nbsp; </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="font-variant-ligatures: no-common-ligatures; color: #000000">&nbsp; &nbsp; </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;">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">func</span> find(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@noescape</span> predicate: (<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">Self</span>.Generator.Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa">Bool</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">rethrows</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa">Self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa">Generator</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa">Element</span>? {</p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">for</span> elt <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span> {</p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">try</span> predicate(elt) {</p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">return</span> elt</p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span></p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; }</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</div>
</div>
<div>&nbsp;</div>
</body>
</html>