Ruckus
04/11/2022, 6:48 PMRuckus
04/11/2022, 6:52 PMoperator fun <T> T.invoke(action: context(T) () -> Unit) {
action(this)
}
This works:
val action: context(String) () -> Unit = {
length
}
"Test"(action)
but inlining action
does not:
"Test" {
length // Unresolved reference: length
}
Ruckus
04/11/2022, 6:54 PMdmitriy.novozhilov
04/11/2022, 6:55 PMRuckus
04/11/2022, 7:00 PMYoussef Shoaib [MOD]
04/12/2022, 10:52 AMsealed interface TypeWrapper<out A> {
object IMPL: TypeWrapper<Nothing>
}
operator fun <T> T.invoke(action: context(T) (TypeWrapper<T>) -> Unit) {
action(this, TypeWrapper.IMPL)
}