[Pitch] Enable pack iteration

Aye, but it can be annoying to have to do that. For instance, within the loop body, I may want to write things like:

let value: ElementType

if thing { 
  value = ...
} else {
  value = ...
}

// or:

var values = [ElementType]()

There are tricks, but it doesn't feel as harmonious when you're forced to adapt your regular coding style to gaps in the language. This kind of code works in other generic contexts, but in these contexts you need to use a more awkward formulation due to not being able to give the element type a name.

The inability to introduce local generic types has been a hole in the language for a long time, and it significantly affects the ergonomics of both variadic generics and existentials. That is why, a long time ago, I suggested that this feature would actually be a good first step towards introducing variadic generics, and I mention it at every opportunity since then :slight_smile::

So as nice as this feature is (and it is very nice), I kind of do need to express some slight disappointment that we're not truly tackling local generic types while we do it. Instead, we're carrying on the trend of making generic type parameters unutterable - and in doing so, needlessly restricting the kinds of patterns developers are able to express.

I'm fully okay with that being a future direction, but I think we should acknowledge that pack iteration is not "finished" until we can name the generic types bound on each iteration of the loop.

2 Likes