lokesh
07/22/2026, 4:05 PMChrimaeon
07/22/2026, 4:29 PMCasey Brooks
07/22/2026, 5:07 PMinterface MyCallback {
fun doAThing(s: String)
}
fun doSomethingAsync(onComplete: MyCallback) {
onComplete.doAThing("done")
}
class MainClass : MyCallback {
fun runMain() {
doSomethingAsync(this)
}
override fun doAThing(s: String) {
println(s)
}
}
And if you define the interface as a fun interface, then you can give the caller the choice to use either the Interface or lambda syntax:
fun interface MyCallback {
operator fun invoke(s: String)
}
fun doSomethingAsync(onComplete: MyCallback) {
onComplete("done")
}
fun runMain() {
doSomethingAsync {
println(it)
}
}Casey Brooks
07/22/2026, 5:08 PMFunction1<T1, R>, Function2<T1, T2, R>, etc), . It's just a syntax thinglokesh
07/23/2026, 7:43 AMCLOVIS
07/23/2026, 8:07 AM"don't be hard on yourself and move to discord" guys please 🙏😔Discord added Slack-like threads a few years ago 😅
I can't pass independent functions like JS or any highly functional-sided programming language.You can;
fun foo(e: () -> Unit) = …
foo { println("hello") }
This is passing a function directly. It's the same as in JS.
You can also pass function references:
fun bar() {
println("hello")
}
foo(::bar)
Again, that's the same as in JSlokesh
07/23/2026, 9:31 AMlokesh
07/23/2026, 9:31 AM