Hi, why can't I use a vararg argument for a typeal...
# announcements
a
Hi, why can't I use a vararg argument for a typealias of a function ?
y
Using an
Array<out T>
is equivalent to using
vararg param: T
, and then you can also provide a convenient extension function like this: (playground)
Copy code
typealias VarargFun<E, R> = (items: Array<out E>) -> R
operator fun <E, R> VarargFun<E, R>.invoke(vararg items: E): R = this(items)

fun testVararg(vararg test: Any?) = listOf(*test)

fun main(){
    var test: VarargFun<Any?, List<Any?>> = ::testVararg
    println(test("hello", "world"))
}
a
Nice it works, thanks !
t