[swift-evolution] [Pitch?] Way to declare a Swift Array that guarantees it can't be empty

Charlie Monroe charlie at charliemonroe.net
Tue Aug 8 06:57:06 CDT 2017

I had a similar though some time ago (and even suggested it here) - as e.g. "Hello".components(separatedBy: "123") will always produce a non-empty array. Even "".components(separatedBy: "") is [""].

Which would allow e.g. first, last and some other members to loose the optionality - which would be great. But would probably add unnecessary complexity to the stdlib.

Fixed-size arrays do not solve this particular issue that I've noted above.

> On Aug 8, 2017, at 1:39 PM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> I think it would make sense to have arrays with a minimal size, but wouldn't consider it very important.
> But there is a long-running discussion about fixed-size arrays, and depending on (if any) solution is chosen for them, your use case could be solved rather easy as well.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list