<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="">Users who don’t get the single-pass nature of SequenceType may expect a .last as well.<div class=""><br class=""></div><div class=""><div><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:</div><br class="Apple-interchange-newline"><div class="">
<title class=""></title>
<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 style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="" class=""> </span>SequenceType<span style="" class=""> {</span></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.</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)</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 style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="" class=""> first: </span>Self<span style="" class="">.</span>Generator<span style="" class="">.</span>Element<span style="" class="">? {</span></div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> gen = <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">generate</span>()</div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> gen.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">next</span>()</div><div style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" 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</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=AdkfTiApI80cNEyortTzHb2fcfA247JB3qOAr5hAOEEqDJTdNf099UQg7dWn16UwkkUdulTCjafh1C1f7E50OnBp1qXCdnwpwm8nOQsl8Dcz2woY4CqNwrHYQVZY9QMDfcEYeQ9bMzZHsNfHajah32KIgeakUhDE8Bi4wTUKodWmjMcBBBVdH5303FRC18YGsnKH-2F-2FGj55YmFYfVGR-2BB0Q-3D-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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>