<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I think it’s pretty clear that if we have a syntax for passing an array to a variadic argument it should be:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func(array…)</div><div class=""><br class=""></div><div class="">This would be symmetric with variadic type signature, and similar to how other languages do it (i.e. in Ruby, declaration is `*args` and array splat is also `*args`). The operator is necessary for disambiguation (in the `Any…` case and the like).</div><div class=""><br class=""></div><div class="">My guess is that it just hasn’t been implemented, but if we get a formal proposal, then maybe we can put it to review and then it shouldn’t be hard to get it implemented in Swift 3.0 timeframe.</div><div class=""><br class=""></div><div class="">The `…` operator would also be great in a different, but similar case — tuple splat, i.e. if you have a function `(T, U) -&gt; Whatever`, and a tuple `(T, U)`, you could pass it to the function using `function(tuple…)`. (Implicit tuple splat was removed…)</div><div class=""><br class=""></div>Best,<br class=""><div class="">
<div class="">— Radek</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 17 Apr 2016, at 19:12, Justin Jia via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi!<br class=""><br class="">Currently, we can’t call a variadic function with an array of arguments.<br class=""><br class="">Reference:<br class="">1.&nbsp;<a href="http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift" class="">http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift</a><br class="">2.&nbsp;<a href="https://www.drivenbycode.com/the-missing-apply-function-in-swift/" class="">https://www.drivenbycode.com/the-missing-apply-function-in-swift/</a><br class=""><br class="">Consider the following use case:<br class=""><br class="">```<br class="">func average(numbers: Double…) -&gt; Double {<br class="">&nbsp;&nbsp;&nbsp;return sum(numbers) / numbers.count // Error: Cannot convert value of type ‘[Double]’ to expected argument type ‘Double'<br class="">}<br class=""><br class="">func sum(numbers: Double...) -&gt; Double { … }<br class="">```<br class=""><br class="">Right now, there are two ways to fix it:<br class=""><br class="">1. Add another function that accept `[Double]` as input.<br class=""><br class="">```<br class="">func average(numbers: Double…) -&gt; Double {<br class="">&nbsp;&nbsp;&nbsp;return sum(numbers) / numbers.count<br class="">}<br class=""><br class="">func sum(numbers: Double...) -&gt; Double {<br class="">&nbsp;&nbsp;&nbsp;return sum(numbers)<br class="">}<br class=""><br class="">func sum(numbers: [Double]) -&gt; Double { … }<br class="">```<br class=""><br class="">2. Implement an `apply()` function using `unsafeBitCast`.<br class=""><br class="">```<br class="">func average(numbers: Double…) -&gt; Double {<br class="">&nbsp;&nbsp;&nbsp;return sum(apply(numbers)) / numbers.count<br class="">}<br class=""><br class="">func sum(numbers: [Double]) -&gt; Double { … }<br class=""><br class="">func apply&lt;T, U&gt;(fn: (T...) -&gt; U, args: [T]) -&gt; U {<br class="">&nbsp;&nbsp;&nbsp;typealias FunctionType = [T] -&gt; U<br class="">&nbsp;&nbsp;&nbsp;return unsafeBitCast(fn, FunctionType.self)(args)<br class="">}<br class="">```<br class=""><br class="">However, both solutions are not very elegant. The first solution requires the library author to implement both functions, and the second solution breaks the guarantees of Swift’s type system.<br class=""><br class="">Swift should allow passing an array to variadic functions, or we should somehow implement a type-safe `apply()` function in the standard library.<br class=""><br class="">Justin</div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>