[swift-evolution] array splatting for variadic parameters

Haravikk swift-evolution at haravikk.me
Wed Feb 15 03:18:43 CST 2017


> On 14 Feb 2017, at 20:43, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 2017-02-14 18:32 GMT+03:00 Dimitri Racordon via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
> 
> 
> 
> The proposal is indeed really interesting.
> I would love to see if it could get a second round of discussion.
> 
> However, I failed to understand the syntax of the proposed extension. Where would be defined the label and parameter names? Is this just a typo?
> 
> func someFunc<I:IteratorProtocol where I.Element == Int)
> 
> 
> “Obviously”, the Collection variant should look like:
> 
> func someFunc<C: Collection where C.Iterator.Element == Int>(_ values: @variadic C) { … }
> And the others are analagous.
> 

Thanks for the correction, not entirely sure how that mistake made it into the proposal!

I didn't get an especially positive response to the proposal at the time, but it is still very much my preferred solution.


"Splatting" as the OP suggests is a simpler solution, but leaves variadics limited to a unique syntax with no control over type; I'm also not keen on re-using ellipsis as an operator for it, since it's also used for handling ranges, though that's not a major overlap. But still, part of why I made my proposal is that splatting feels more like a workaround to a problem of there not being a proper array/sequence/etc. signature for the function.

I could of course be biased, but then I've never really supported variadics as a feature in the first place 😏
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170215/706cd78a/attachment.html>


More information about the swift-evolution mailing list