<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>I think</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; subviews.find{ ($0 as? NSButton)?.state == NSOnState } as? NSButton</div><div><br></div><div>is sufficient and makes it clear that you are searching for a specific type. Even though you have to cast twice I don't think an additional method would be worth its use since it isn't used as often.</div><div><br></div><div>- Maximilian</div><div><br>Am 17.02.2016 um 10:32 schrieb Marco Masser via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">I just saw this PR and have a quick comment about the implementation: It could be shortened by a few lines using a&nbsp;<span style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;" class="">where</span>&nbsp;clause like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> find(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span><span style="font-variant-ligatures: no-common-ligatures" class=""> predicate: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Generator</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Generator</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span><span style="font-variant-ligatures: no-common-ligatures" class="">? {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> element </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures" class=""> predicate(element) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> element</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class="">Also, I’d like suggest adding a variant that works better with heterogenous sequences, but I’ll raise that when this proposal goes into review.</div><div class=""><br class=""></div><div class="">FYI: That variant would look like this:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> find&lt;T&gt;(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">.Type, </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span><span style="font-variant-ligatures: no-common-ligatures" class=""> matching predicate: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">?</span></div></div><div class=""><br class=""></div><div class="">A question by me on the swift-users mailing list describes its intention, implementation, and usage:</div><div class=""><a href="https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160118/000893.html" class="">[swift-users] Which is the more idiomatic approach for pinning down        the type of a generic parameter?</a></div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Marco</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 2016-01-10, at 01:58, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">


<title class=""></title>

<div class=""><div class="">Proposal PR submitted as&nbsp;<a href="https://github.com/apple/swift-evolution/pull/94" class="">https://github.com/apple/swift-evolution/pull/94</a><br class=""></div>
<div class="">&nbsp;</div>
<div class="">-Kevin Ballard<br class=""></div>
<div class="">&nbsp;</div>
<div class="">On Tue, Dec 29, 2015, at 06:38 PM, Kevin Ballard wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">I'm proposing a new extension method on SequenceType called find(). It's similar to CollectionType.indexOf() except it returns the element:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span class="colour" style="color:rgb(187, 44, 162)">extension</span><span class="colour" style=""></span>SequenceType<span class="colour" style=""> {</span><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(144, 45, 208);" class=""><span class="colour" style=""></span>/// Returns the first element where `predicate` returns `true`, or `nil`<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(144, 45, 208);" class=""><span class="colour" style=""></span>/// if such value is not found.<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><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 class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><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 class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><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 class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="colour" style="color:rgb(187, 44, 162)">return</span> elt<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="colour" style="color:rgb(187, 44, 162)">return</span> <span class="colour" style="color:rgb(187, 44, 162)">nil</span><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}<br class=""></div><div class="">&nbsp;</div>
<div class="">-Kevin Ballard<br class=""></div>
</div>
<div class="">&nbsp;</div>
</blockquote><div class="">&nbsp;</div>

<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=K9qmNlgbKPPmGnoyPaIDeacyynE-2BO94GI4Zq4mx9Z8RsQ781eIpwpUIG0Ep5hjEwkVddrJIJNcl3m0s7shrwLVBb1Po7Pg9yHoJRGz8LGWM9GUC9ukWRdbMDyzxoBLGkIL-2BZWsSzK6VQiHf3CYSiKXkbqZdKmgDya-2BmLEe7XjY1ggKweePDl-2B-2FvepJ6QGHsHmfN7Z5LhDI0HmxAQUMQFH-2B2eHjgUoRHU1TlaxjwCIq0-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;" class="">
</div>


_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></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>