Val function with generic types

Hi everyone, I wonder if it’s possible to add the feature of use val funcions with generic types like this:
If you have for example:
fun <A> makePair(a: A): Pair<A, A> = a to a
do this
val makePairValue = ::makePair or create a val directly like this
val <A> makePair: (A) -> Pair<A, A> = { it to it }

What do you think?

1 Like

There’s not really a good reason to do this. You can already do this:

fun <T> T.makePair(): Pair<T, T> = this to this

as well as the example you mentioned above. You can created generic typed lambda variables in classes that have a generic type:

class Something<T> {
    val variable: (T) -> Pair<T, T> = { it to it }

Ok, probably you’re right, I can rewrite it in another way or wrapping it in some class, but it feels odd to me to allow some function values and not others.
I’ll think if there is another use case where this becomes useful, in the meantime I will use your suggestions

Thanks @nlbuescher