We can write functional interfaces in Kotlin like this - function-interfaces
fun interface Sum {
fun add(a: Int, b: Int): Int
}
val sumImpl = Sum { a, b ->
return@Sum a + b
}
val testSum = sumImpl.add(4, 5)
How can we write Jetpack Composable function in same way? Below code is not working. `
fun interface SampleText {
@Composable
fun text(data : String)
}
val textImpl = SampleText { data ->
return@SampleText @Composable { Text(data) }
}
@Composable
fun testText() = textImpl.text("Data")
I have tried this as well, but this also didn't work.
fun interface SampleText {
fun text(data : String) : @Composable () -> Unit
}
val textImpl = SampleText { data ->
@Composable { Text(data) }
}
@Composable
fun testText() = textImpl.text("Data")