I’m looking for an idiomatic way to convert object + method to function. Example:
val o = "test"
val f: () -> String = {o.toString()}
Java has method reference, so I could write o::toString
, but Kotlin for some reason doesn’t have it.
Currently I’m using the following extension function:
fun <T, R> T.bind(method: T.() -> R): () -> R = {this.method()}
val o = "test"
val f: () -> String = o.bind { toString() }
but I would prefer something from a standard library. I tried to find something similar, but I couldn’t find anything.