<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Here it is <a href="https://github.com/apple/swift/blob/master/stdlib/public/core/CollectionAlgorithms.swift.gyb#L26" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/CollectionAlgorithms.swift.gyb#L26</a></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 30, 2015, at 4:27 PM, Kevin Ballard <<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<title class=""></title>
<div class=""><div class="">We already don't have a .last on CollectionType and nobody's been complaining about that. Besides, sequences don't necessarily even terminate.<br class=""></div>
<div class=""> </div>
<div class="">-Kevin Ballard</div>
<div class=""> </div>
<div class="">On Wed, Dec 30, 2015, at 04:01 PM, Daniel Duan wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">Users who don’t get the single-pass nature of SequenceType may expect a .last as well.<br class=""></div>
<div class=""> </div>
<div class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 30, 2015, at 3:57 PM, Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div>
<div class=""> </div>
<div class=""><div class=""><div class="">It's sometimes useful to get the first element of a sequence. To that end I'd like to propose<br class=""></div>
<div class=""> </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 style="" class=""></span>SequenceType<span style="" class=""> {</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 style="" class=""></span>/// Returns the first element of `self`, or `nil` if `self` is empty.<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 style="" class=""></span>/// - Complexity: O(1)<br class=""></div>
<div style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112, 61, 170);" class=""><span style="" class=""></span><span class="colour" style="color:rgb(187, 44, 162)">var</span><span style="" class=""> first: </span>Self<span style="" class="">.</span>Generator<span style="" class="">.</span>Element<span style="" class="">? {</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)">var</span> gen = <span class="colour" style="color:rgb(61, 29, 129)">generate</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)">return</span> gen.<span class="colour" style="color:rgb(61, 29, 129)">next</span>()<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 style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;" class="">}<br class=""></div>
<div class=""> </div>
<div class="">I think it makes sense to add this property to the definition of SequenceType as well, so various sequences can override it to avoid constructing a generator.<br class=""></div>
</div>
<div class=""> </div>
<div class="">With this added to SequenceType, we can remove it from CollectionType, as the behavior will be the same.<br class=""></div>
<div class=""> </div>
<div class="">-Kevin Ballard<br class=""></div>
<div class=""><img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/8cd6358bea2623e51d84aa288ae461fd69f8bdddc4531283960ff23340e3275f/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d31446b6664596140794830336e45497f6274745a784262366366614234373a4243317f41427538614f454541744a44546e466039393551576734675e613635577b6b6554657c64534a61666861334136673545303f4e624071317853446e6770777d683e6f41537c6834436a72377f695433417e4772784951565a5959315d4446636549556159326d4a7a58437e4668416a616863323b494765616b65586445483249643774555b4f64675d6a6d436242424654684533303336425341383957437e6b484d22364d2236474a6535395d6649566657425d22324240315d23344d23344/open" class=""><br class=""></div>
</div>
<div class="">_______________________________________________<br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div>
</div>
</blockquote></div>
</div>
</blockquote><div class=""> </div>
</div>
</div></blockquote></div><br class=""></div></body></html>