[swift-evolution] [Proposal] Allow passing a variadic parameter to another variadic function
Christopher Boyd
xpboyd at gmail.com
Fri May 20 10:19:47 CDT 2016
Currently, Swift doesn't have a way to easily pass a variadic parameter to
another variadic function because the variadic parameter itself has already
been collected into an array.
There was a prior posting a few weeks back about allowing arrays to be
passed to a variadic parameter which would resolve this very specific issue:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160411/015185.html
Unfortunately, that thread devolved into an argument on whether or not
variadic parameters should be removed entirely.
I, certainly, see merit in having functions that can accept a variable
number of arguments and variadic functions should seem intuitive to anyone
else that might be reading the code.
Swift's documentation presents a very intuitive example:
1. arithmeticMean(1, 2, 3, 4, 5)
It's obvious what this function is doing, and any intelligent person would
expect 3 as the result. Even WolframAlpha knows how to interpret this:
http://www.wolframalpha.com/input/?i=arithmeticMean(1,+2,+3,+4,+5)
Moreover, a function can only have ONE variadic parameter, which I think
reduces any possible confusion.
Regardless, if variadic parameters are going to stay in Swift, then I think
they should at least support chaining to another function.
The most obvious way of allowing this would be to allow variadic parameters
to accept an array.
However, I think that if an array (of the parameter type) is specified for
a variadic parameter, then no other values should be allowed. This
eliminates any unnecessary complexity of potentially having to add values
to the array.
- Christopher Boyd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160520/b82e9814/attachment.html>
More information about the swift-evolution
mailing list