<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="">Hello,<div class=""><br class=""></div><div class="">My two cents: I feel uncomfortable with SequenceType.first since SequenceType clearly states that it may be destructed on iteration.</div><div class=""><br class=""></div><div class="">Compare :</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);" class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">seq</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">generate</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">().</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">next</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">() </span>// clear that it may give another result if called twice</div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">seq</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.first &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>// unclear that it may give another result if called twice</div></div></div><div class=""><div><div class=""><div class=""><br class=""></div><div class="">Gwendal</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);" class=""></div></div></div><blockquote type="cite" class=""><div class="">Le 31 déc. 2015 à 00:57, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</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="">&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 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="">&nbsp; &nbsp; </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="">&nbsp; &nbsp; </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="">&nbsp; &nbsp; </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="">&nbsp; &nbsp; &nbsp; &nbsp; <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="">&nbsp; &nbsp; &nbsp; &nbsp; <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="">&nbsp; &nbsp; }</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="">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="">&nbsp;</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="">&nbsp;</div>
<div class="">-Kevin Ballard</div>

<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=GUvuDT95GpxW2sIYHiKg6obX3uIIobaj9awaKuut6Z9oxSFRdiO-2BQ63IyVjL2rSLpf1d5swUHNi3-2FPmPqTF8Yz3Dmk3QpR1DqooiO5VZeJ6lkhAIETdKV2KdlqMGbFqxxahsTktJ4haZbStIwmtVf2Po-2BiXTnK-2FgkyyaCV2hATH9ca5AbQlZtjbXu9wvjC6E79rVtMDC-2Bzb5R2NT63LH7z-2FIFohRdlcD6czbtfX0XMU-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>