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 {

There also exists a popFirst() function, but what I find inconsistent is that 
popFirst() is only available on ArraySlice.

var collection = [1, 2, 3, 4]
collection.removeFirst() // works fine
collection.removeLast() // works fine
let last = collection.popLast() // works fine
let first = collection.popFirst() // Compile error: [Int] is not convertible to 

Is it intended that popLast() is available on collections, but popFirst() is 

– Louis D'hauwe
swift-evolution mailing list

Reply via email to