<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="">Correct me if I’m wrong but a variadic argument is guaranteed to have one or more elements in the array. Isn’t that the case? As an example, consider the following initializer:</div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; min-height: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(state: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">State</span><span style="font-variant-ligatures: no-common-ligatures" class="">, actions: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Action</span><span style="font-variant-ligatures: no-common-ligatures" class="">...) {</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> <font color="#4f8187" class="">// ...</font></span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">Here, I can count on <span style="font-family: Menlo; font-size: 13px;" class="">actions</span> to be a non-empty array. It’s self-documenting and type-safe. How would this work if arrays are (implicitly or explicitly) convertible to variadic arguments?</div><div class=""><br class=""></div><div class="">R+</div><br class=""><div><blockquote type="cite" class=""><div class="">On 26 Feb 2017, at 17:26, Derrick Ho via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">In swift, a variadic argument can become an array without too much effort.<div class=""><br class=""></div><div class="">func foo(_ va: String...) {</div><div class=""> let a: [String] = va</div><div class="">}</div><div class=""><br class=""></div><div class="">However, it seems odd to me that an array can not be converted into a variadic argument</div><div class=""><br class=""></div><div class="">foo(["a", "b", "c"]) // <-error</div><div class="">foo("a", "b", "c") // no error<br class=""></div><div class=""><br class=""></div><div class=""><a href="http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift" class="">Other people have wondered about this too.</a><br class=""></div><div class=""><br class=""></div><div class="">According to <a href="https://devforums.apple.com/message/970958#970958" class="">this thread</a> Doug Gregor says it is due to some type ambiguity. with Generics.</div><div class=""><br class=""></div><div class="">If type ambiguity is the issue, Do we have the option to cast it to the correct type?</div><div class=""><br class=""></div><div class="">foo(["a", "b", "c"] as String...) // <- error. doesn't consider String... to be a type.<br class=""></div><div class=""><br class=""></div><div class="">What does the community think? Should we be granted some mechanism to turn an array into a variadic argument?</div></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>