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

Louis D'hauwe louisdhauwe at silverfox.be
Tue Oct 18 13:16:29 CDT 2016

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 'ArraySlice<Int>'

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

– Louis D'hauwe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161018/77b7e84c/attachment.html>

More information about the swift-evolution mailing list