Re: [swift-evolution] [stdlib] Collection mutators availability inconsistent

2016-10-18 Thread Dave Abrahams via swift-evolution
on Tue Oct 18 2016, Max Moiseev wrote: > Hi Louis, > > I believe the difference is due to the performance guarantees. One can > only efficiently implement `popFirst` and `removeFirst` on slices, > where it’s just a matter of index manipulation. Well, and on deques, doubly-linked lists, and cir

Re: [swift-evolution] [stdlib] Collection mutators availability inconsistent

2016-10-18 Thread Max Moiseev via swift-evolution
Hi Louis, I believe the difference is due to the performance guarantees. One can only efficiently implement `popFirst` and `removeFirst` on slices, where it’s just a matter of index manipulation. Removing the first element of a Collection is potentially an O(n) operation. Using `popFirst` in a

[swift-evolution] [stdlib] Collection mutators availability inconsistent

2016-10-18 Thread Louis D'hauwe via swift-evolution
Collections have mutating functions for removing the first and last element. One of these is popLast(), which will safely check if the collection is empty before popping the last element. So calling popLast() is like doing: if !collection.isEmpty { collection.removeLast() } There also ex