<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 6, 2016 at 1:15 PM, Rod Brown via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><span></span></div><div><div>You wouldn&#39;t ever <i>need</i> for it to be non optional as it simply could be unwrapped with !</div><div><br></div><div>That said, there is a decent risk that developers might often get into a habit of forcibly unwrapping the value when the are removing items from arrays where they expect it to have content and it unexpectedly doesn&#39;t.<br></div></div></div></blockquote><div><br></div><div>Isn&#39;t there exactly the same risk with removeFirst() as it exists today? Arguably even riskier, because there&#39;s no &quot;!&quot; to warn you that it might crash?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div>I think in regards to arrays, there is a decent history of user/dev responsibility to run those checks, and if you don&#39;t, there is an out of bounds exception. The check is simply your responsibility. This is designed to promote you to maintain awareness about how many items are in the array at all times, as mismanaged arrays are a cesspool of bugs. If we go through and put an optional here, wouldn&#39;t it make sense to make the return values of subscripting also optional? I think this is an all-or-nothing thing.</div><div><div class="h5"><div><br>On 7 Jan 2016, at 6:12 AM, James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">I personally would love to have it as optional behaviour. Not sure when you would ever need it to be non optional ? </div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 6:54 PM, Max Moiseev <span dir="ltr">&lt;<a href="mailto:moiseev@apple.com" target="_blank">moiseev@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Ahhh, right.<div><br><div>I believe the thinking here is that since this is an avoidable error, it should be handled in the client code with an `if !array.isEmpty { … }`), leaving errors to really exceptional and unexpected conditions.</div><div>Using optional here will serve the same purpose, IMHO, but instead of preventing the condition, one would have to react to the consequences later. Moreover the type will now be Optional&lt;Element&gt; and it would also be really tempting to write something like `array.removeFirst()!` and have the same trapping behavior.</div><div><br></div><div>Dave, Dmitri, please correct me if I’m wrong.</div><span><font color="#888888"><div><br></div><div>max</div></font></span><div><div><div><br><div><blockquote type="cite"><div>On Jan 6, 2016, at 10:34 AM, James Campbell &lt;<a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>&gt; wrote:</div><br><div><div dir="ltr">What I mean&#39;t is it would be great is if it was a native swift error :) so we could use try? syntax.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 6:32 PM, Max Moiseev <span dir="ltr">&lt;<a href="mailto:moiseev@apple.com" target="_blank">moiseev@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi James,<div><br></div><div>I believe <a href="https://github.com/apple/swift/blob/master/stdlib/public/core/RangeReplaceableCollectionType.swift#L235" target="_blank">this code</a> already handles empty array scenario by failing if the precondition is not met.</div><div>Or do you have something else in mind?</div><div><br></div><div>max</div><div><br><div><blockquote type="cite"><div><div><div>On Jan 6, 2016, at 9:36 AM, James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div><div dir="ltr">If you call removeFirst and the array is empty it would be great if it was optional so it could return nil or at least it threw an error so you could handle that case.<br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank">+44 7523 279 698</a></div></div></div></div></div></div>
</div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZdiBPeKLcE1ZkxjSogRct0bur3WJrrZggvfZYd5wkdIp5FK734JzyuHDaQTKyyfFUl4Oetpv6m-2BbZl9vCejfAtdKcEccAHavkeM-2FQ-2BGNbCj3zofZsTXWHdFNOT5ZSWyTgcU3aa6-2FXHdaIJGJa5eDVO6RIWnNE39ULsgVA13-2FQQQ5yg-2F8NG99YRPYv-2FH0X00Ji86j38e11VyPJKC9ohGYRHhByX5bowmORio6Ge02ooM-3D" alt="" width="1" height="1" border="0" style="min-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">
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank">+44 7523 279 698</a></div></div></div></div></div></div>
</div>
</div></blockquote></div><br></div></div></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank">+44 7523 279 698</a></div></div></div></div></div></div>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=a745LmqnDfg8U5xkzxO94fzXSZ0ZB2d7MXjmVBHs4IHYS2WgYLpVRyq6XkZs-2BRPI1gS1EuJ38BBU7uGxkNpJlJ8yNHol-2FEKph7l3AglEtwq-2FV1DBQov64tV7fHqEphUBVGMIZLSShCkio2IWvBnKvapdFOERGsOM1wgC2nu2N0c8WwaHPj81anBBObKGAb4tOg3TfveQrw-2Bn7TpzeefXxRimEsOW041KRgoXABI27Aw-3D" alt="" width="1" height="1" border="0" style="min-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">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=P-2BsYbBZHRBuLDBJaL4DIKDNfkkjpROowTyRAObV11qwWI56dxWMmWmZfzABLR4y8TLu7ZfUR2pjuArTHctA5cFAYM6cMN-2BjlCviawJlrKIVqgWDPGkjrh23v-2BuU1-2FhmnAFUYXU2kehckj1bEx-2FPV-2B3sEdi77yAHemrQgZqXi9-2BUvH1TgvL1jeYpXL6mgPJm18124OLq9C94KCTC7PQ-2F84Xk-2BwPRBfenHim16hxfJOSc-3D" alt="" width="1" height="1" border="0" style="min-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">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div><div class="gmail_extra">Jacob</div></div>