Why not remove varargs altogether from Swift, it is easy enough to put [] round a list?<br><br>On Monday, 18 April 2016, Keith Smiley via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We&#39;ve been dealing with this as well. We&#39;ve chosen to go with your option 1 for<br>
most of our cases, sometimes dropping varargs all together and just using the<br>
array signature.<br>
<br>
It would be great if you could have a safe apply function for this.<br>
<br>
--<br>
Keith Smiley<br>
<br>
On 04/17, Justin Jia via swift-evolution wrote:<br>
&gt; Hi!<br>
&gt;<br>
&gt; Currently, we can’t call a variadic function with an array of arguments.<br>
&gt;<br>
&gt; Reference:<br>
&gt; 1. <a href="http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift" target="_blank">http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift</a> &lt;<a href="http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift" target="_blank">http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift</a>&gt;<br>
&gt; 2. <a href="https://www.drivenbycode.com/the-missing-apply-function-in-swift/" target="_blank">https://www.drivenbycode.com/the-missing-apply-function-in-swift/</a> &lt;<a href="https://www.drivenbycode.com/the-missing-apply-function-in-swift/" target="_blank">https://www.drivenbycode.com/the-missing-apply-function-in-swift/</a>&gt;<br>
&gt;<br>
&gt; Consider the following use case:<br>
&gt;<br>
&gt; ```<br>
&gt; func average(numbers: Double…) -&gt; Double {<br>
&gt;    return sum(numbers) / numbers.count // Error: Cannot convert value of type ‘[Double]’ to expected argument type ‘Double&#39;<br>
&gt; }<br>
&gt;<br>
&gt; func sum(numbers: Double...) -&gt; Double { … }<br>
&gt; ```<br>
&gt;<br>
&gt; Right now, there are two ways to fix it:<br>
&gt;<br>
&gt; 1. Add another function that accept `[Double]` as input.<br>
&gt;<br>
&gt; ```<br>
&gt; func average(numbers: Double…) -&gt; Double {<br>
&gt;    return sum(numbers) / numbers.count<br>
&gt; }<br>
&gt;<br>
&gt; func sum(numbers: Double...) -&gt; Double {<br>
&gt;    return sum(numbers)<br>
&gt; }<br>
&gt;<br>
&gt; func sum(numbers: [Double]) -&gt; Double { … }<br>
&gt; ```<br>
&gt;<br>
&gt; 2. Implement an `apply()` function using `unsafeBitCast`.<br>
&gt;<br>
&gt; ```<br>
&gt; func average(numbers: Double…) -&gt; Double {<br>
&gt;    return sum(apply(numbers)) / numbers.count<br>
&gt; }<br>
&gt;<br>
&gt; func sum(numbers: [Double]) -&gt; Double { … }<br>
&gt;<br>
&gt; func apply&lt;T, U&gt;(fn: (T...) -&gt; U, args: [T]) -&gt; U {<br>
&gt;    typealias FunctionType = [T] -&gt; U<br>
&gt;    return unsafeBitCast(fn, FunctionType.self)(args)<br>
&gt; }<br>
&gt; ```<br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; Swift should allow passing an array to variadic functions, or we should somehow implement a type-safe `apply()` function in the standard library.<br>
&gt;<br>
&gt; Justin<br>
<br>
&gt; _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;swift-evolution@swift.org&#39;)">swift-evolution@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
</blockquote><br><br>-- <br>-- Howard.<br>