Named arguments for Funtional Types

Hi all,

today kotlin supports typealias for functional types:

typealias MyFunction = (String) -> Unit

we can also define a parameter name, to improve documentation and help the IDE:

typealias MyFunction = (userId: String) -> Unit

what we cannot do is to call myFunction using a named argument:

val myFunction: MyFunction = { userId -> 
    //do something with userId
}

myFunction(userId = "123") //This does not work

can this functionality be added to the compiler?
I understand that it would mean a whole change, as the typealias does not add a new type to the system.
I guess that with a bit of syntax sugar something like:

fun interface MyFunction: (userId: String) -> Unit

could be introduced, and be compiled to:

fun interface MyFunction {
    operator fun invoke(userId: String)
}

but today, (userId: String) -> Unit cannot be used as supertype

2 Likes