Hi Christopher, Do you think something like this would work if there was a #splat() magic operator like this:
let values = [1, 2, 3, 4, 5] let mean = arithmeticMean(#splat(values)) > On May 20, 2016, at 11:19 AM, Christopher Boyd via swift-evolution > <[email protected]> wrote: > > 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: > 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 > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
