This isn't a fully formed pitch, and maybe already discussed, but...

If we have have optionals and non-optionals, shouldn't we also have a way
to declare that an Array never be empty? It seems like this would naturally
lead to more elegant designs.

Here's a use-case:

struct Wavelet {
var buff: [Double]
var sign: Sign
var peak: Double {
return buff.find_max()! // <-- Yuck!

In my app, I never want to create an empty "buff" here. If I could declare
that the Array always contain at least 1 element, I wouldn't need to worry
about a whole bunch of unwrapping elsewhere in my program. Native ability
to do this would also be handy to store chunks of memory, too?

Would this be worthwhile?
swift-evolution mailing list

Reply via email to