Variadic Generics

I sorta regret writing the example in that way. Swift shouldn't need the prefix "...", and that definition of items is probably wrong. If we're using "...", that example should likely be written as:

struct Variadic<T...> {
  var items: (T...)
}

Same thing here:

we don't need the prefix "...", and probably don't even want the notion of it in the language. iterators can be described as:

var iterators: (Iterators...)

so we're forming a tuple type from the types in Iterators and storing that.

You are correct; my example here was bogus. I'll take a pass through this part of the generics manifesto so at least it's not as misleading and wrong. Thank you!

This may not work so well in a generic context unless you had a way to say "I know that someTuple has at least one element".

When it comes to tuple splatting, I think what we really want is a way to take a tuple and expand it into N separate arguments, e.g.,

let someTuple = (1, 3.14159, "Hello")
f(someTuple...). // equivalent to f(1, 3.14159, "Hello")

It's plausible that we could integrate that with variadic generics if, say, a "function parameter pack" was represented as a tuple and all tuples could be expanded like that.

Doug

9 Likes