Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread Max Moiseev via swift-evolution
Hi James, I believe this code already handles empty array scenario by failing if the precondition is not met. Or do you have something else in mind? max > On Jan 6, 2016, at 9:36 AM,

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread James Campbell via swift-evolution
What I mean't is it would be great is if it was a native swift error :) so we could use try? syntax. On Wed, Jan 6, 2016 at 6:32 PM, Max Moiseev wrote: > Hi James, > > I believe this code >

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread James Campbell via swift-evolution
I personally would love to have it as optional behaviour. Not sure when you would ever need it to be non optional ? On Wed, Jan 6, 2016 at 6:54 PM, Max Moiseev wrote: > Ahhh, right. > > I believe the thinking here is that since this is an avoidable error, it > should be

[swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread James Campbell via swift-evolution
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. --  Wizard ja...@supmenow.com +44 7523 279 698 ___ swift-evolution mailing list

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread James Campbell via swift-evolution
Yeah I was using this for a LIFO type system :) glad to know there is a method for this. On Thu, Jan 7, 2016 at 12:09 AM, Dave Abrahams wrote: > > On Jan 6, 2016, at 3:48 PM, Jacob Bandes-Storch > wrote: > > Whoops, I meant append()/popFirst. That is,

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread Dave Abrahams via swift-evolution
> On Jan 6, 2016, at 3:48 PM, Jacob Bandes-Storch wrote: > > Whoops, I meant append()/popFirst. That is, even for a single-ended queue, > you'll use one "first" operation (less efficient) and one "last" operation. No, a single-ended queue is a stack. You can use append

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread Jacob Bandes-Storch via swift-evolution
Whoops, I meant append()/popFirst. That is, even for a single-ended queue, you'll use one "first" operation (less efficient) and one "last" operation. On Wed, Jan 6, 2016 at 3:47 PM, Dave Abrahams wrote: > > On Jan 6, 2016, at 3:42 PM, Jacob Bandes-Storch

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread Dave Abrahams via swift-evolution
> On Jan 6, 2016, at 3:42 PM, Jacob Bandes-Storch wrote: > > Oops, I forgot this existed. > > I'm assuming you're recommending popLast for performance reasons? > Unfortunately, for a …double-ended… > queue, you'll need either insertAtIndex(0)/popLast or append()/popLast

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread Jacob Bandes-Storch via swift-evolution
I'd be in favor of that, although I imagine it would be very challenging to change the nullability of the return type without wreaking havoc on thousands of lines of legacy code. Having the migrator add "!" wouldn't be all that great. I think there's also precedent in the stdlib for there to be

Re: [swift-evolution] removeFirst, optional equiviliant

2016-01-06 Thread Jacob Bandes-Storch via swift-evolution
On Wed, Jan 6, 2016 at 1:15 PM, Rod Brown via swift-evolution < swift-evolution@swift.org> wrote: > You wouldn't ever *need* for it to be non optional as it simply could be > unwrapped with ! > > That said, there is a decent risk that developers might often get into a > habit of forcibly