[swift-evolution] Proposal for Passing Arrays to Variadic Functions
david at alkaline-solutions.com
Sat Dec 12 13:39:24 CST 2015
> On Dec 12, 2015, at 12:12 AM, Arthur Ariel Sabintsev via swift-evolution <swift-evolution at swift.org> wrote:
> Thanks for your response.
> The reason this doesn't work is due to Swift's generic system as it allows a type T to be a anything, including arrays. The example that was used to delineate this concept to me was that of "Any...", which from within the variadic function, could be interpreted as T or [T]. The result is ambiguous in the current implementation, which is why some identifier syntax needs be passed along with an array to get this to work properly.
> As for the choice of operator, I'm open to suggestions. I wanted to use one that was familiar to other developers, so I chose the one that Ruby uses.
> Maybe a ~ would be better, or a keyword like @variadic?
I was thinking of a second type (VariadicArray<T>, perhaps) which you received in the body of your function instead of Array, and which was not supported via … sequence (so no args: VariadicArray<T>… allowed). However, it looks like this type would have to be fixed, not allowing for protocol compliance (including Any)
Would it be possible to automatically take a function which uses T… and generate the [T] argument version of the function? Today, I just implement the [T] variant and have the T… function do nothing but call it.
More information about the swift-evolution