Variadic Parameters that Accept Array Inputs

Now that SE-0213 has passed, you could solve this by making varargs their own logical type that implicitly converts to (but not from) [Element] with initializers that take an [Element]. The type itself will probably have to remain compiler magic for a while, but that shouldn't be too big of an issue.

// Probably predefined in the standard library. _VarArgs is not meant for direct user access
// because it's wicked black voodoo magic. The function name is just a strawman.
@inlinable
public func splat<T>(_ array: [T]) -> T... {
    return _VarArgs(array) // Converting init.
}

func doAThing(with items: Any...) -> [Any] {
    return items // items implicitly converts from Any... to [Any]
}

let res = doAThing(with: 1, 2, 3)
let res2 = doAThing(with: res) // returns an [Any] whose sole element is an [Any]
let res3 = doAThing(with: splat(res)) // returns the same thing as doAThing(1, 2, 3)
1 Like