https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
d

Daniel Pitts

12/09/2023, 1:04 AM
Are there any proposals for variadic type parameters? Along the lines of
fun <...Types> doThing(block: (Types...)->Unit, args: Types...){ block(*args) }
?
h

hfhbd

12/09/2023, 6:43 AM
How do you use it? How should the compiler check the erased generics at runtime?
c

Chris Fillmore

12/09/2023, 4:32 PM
This use case is usually solved by creating overloads with the number of types you need
It’s boilerplate but variadic types is a bit of a niche use case
d

Daniel Pitts

12/09/2023, 4:33 PM
I'm only asking if there was a proposal for it, not suggesting it would be easy and that there are no other alternatives 😉
The one use-case that is common is for N length Tuples.
c

Chris Fillmore

12/09/2023, 4:34 PM
Ok that I don’t know
m

mikhail.zarechenskiy

12/11/2023, 8:52 AM
There is only an issue for now: https://youtrack.jetbrains.com/issue/KT-31427/Support-variadic-generics Feel free to drop your use-case there. Variadic generics could be a really nice extension of the language, it's a natural generalisation of our
kotlin.Function(N)
functions. However, variadic generics require support of tuples as well, or "multiple returns", so we're kind of limited right now on JVM. We even had a small prototype in the language a few years ago. Here is an [example](https://github.com/KirpichenkovPavel/kotlinx.coroutines/commit/59ac8ac84587a4bc082f72b529620c139735289e#diff-b89b26a9a072f15[…]5f302fea0536d44d0R319) of variadic generics in kotlinx.corourintes