<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><div>You wouldn't ever <i>need</i> for it to be non optional as it simply could be unwrapped with !</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">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't.<br><br></div><div id="AppleMailSignature">I think in regards to arrays, there is a decent history of user/dev responsibility to run those checks, and if you don'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't it make sense to make the return values of subscripting also optional? I think this is an all-or-nothing thing.</div><div><br>On 7 Jan 2016, at 6:12 AM, James Campbell via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> 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"><<a href="mailto:moiseev@apple.com" target="_blank">moiseev@apple.com</a>></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<Element> 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 class="HOEnZb"><font color="#888888"><div><br></div><div>max</div></font></span><div><div class="h5"><div><br><div><blockquote type="cite"><div>On Jan 6, 2016, at 10:34 AM, James Campbell <<a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>> wrote:</div><br><div><div dir="ltr">What I mean'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"><<a href="mailto:moiseev@apple.com" target="_blank">moiseev@apple.com</a>></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 <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> 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 class="gmail_signature"><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>+44 7523 279 698</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="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">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></div></body></html>