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
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
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