*EDIT*: _As <@U8UA78NLC> pointed out, this would a...
# language-proposals
r
EDIT: _As @Ilmir Usmanov [JB] pointed out, this would already be covered by _https://youtrack.jetbrains.com/issue/KT-7770 Proposal: Allow lambda syntax for for interfaces that derive
FunctionX
. I have a use case where I need a "recursive" function type, so I can't use a typealias:
Copy code
typealias Interceptor<T, U> = (Store<T, U>, U, Interceptor<T, U>) -> Unit  // Cannot be done
I can define a specific interface to replace that like so:
Copy code
interface Interceptor<T, U> : (Store<T, U>, U, Interceptor<T, U>) -> Unit
but that interface cannot be used as a lambda:
Copy code
fun <T, U> test(interceptor: Interceptor<T, U>) { ... }

// You have to do this
test(object: Interceptor<String, Int> {
    override fun invoke(store: Store<String, Int>, value: Int, interceptor: Interceptor<String, Int> {
        ...
    }
})

// I would like to do this
test<String, Int> { store, value, interceptor -> ... }
i
Isn't https://youtrack.jetbrains.com/issue/KT-7770 what you are looking for?
r
Ah, I guess it would indeed. For some reason I didn't make the connection earlier. Thanks!
Actually, I guess mine is a little more specific. I actually do not want Java style SAM conversion with Kotlin interfaces, as it kind of defeats the purpose of having functional types in Kotlin. I would limit it to only interfaces that extend
Function
.
u
Another use case for this are methods generated by kapt. To kapt, a lambda is a FunctionX so if an annotation processor takes the signature of a method that accepts a lambda and tries to generate a new method with identical signature it will generate a method with FunctionX parameter type. This makes it then impossible to pass the lambda to this generated method.