Iterate over Parameter Packs in Swift 6.0
swift.org
swift.org
a(x1);
a(x1, x2);
a(x1, x2, x3);
Etc. All the same function but with different numbers of arguments of the same type. I’m not sure how useful it is to everyday programmers, but it lets them fix some messes in the standard library. For example how you can only have 10 (?) things in a VStack in SwiftUI. Why? It was implemented as above because type checked variadic arguments weren’t doable for a reason I’m not sure of.
Now they are.
This also isn’t a problem specific to Swift. Many strongly typed languages run into it.
Examples:
- C# (https://learn.microsoft.com/en-us/dotnet/api/system.tuple-8?...):
public class Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>
- Scala (https://www.scala-lang.org/api/2.13.6/scala/Function22.html): trait Function22[-T1, -T2, -T3, -T4, -T5, -T6,
-T7, -T8, -T9, -T10, -T11, -T12,
-T13, -T14, -T15, -T16, -T17, -T18,
-T19, -T20, -T21, -T22, +R] extends AnyRef
- Java (https://www.javatuples.org/index.html; third party) VStack {
ViewA()
ViewB()
...
ViewJ()
ViewK() // ERROR: A VStack is limited to 10 elements
}
The only way this could be implemented previously was with a separate init for each possible element count. A lot of auto-generated code.This eliminates that. So even if you're not implementing it yourself, you're getting the benefits.