Rob Elliot
03/21/2024, 7:20 PMpackage module1
data class Thing1(val name: String)
package module2
interface Named {
val name: String
}
fun Thing1.asNamed() = object : Named {
override val name: String = <mailto:this@asNamed.name|this@asNamed.name>
}
Rob Elliot
03/21/2024, 7:21 PMJeff Lockhart
03/21/2024, 7:41 PMequals, hashCode and toString are not going to be niceYou could overcome this with a class like this one I use in my KMP library to wrap platform implementations. It also has an
actual
property to access the wrapped object directly.Rob Elliot
03/21/2024, 7:42 PMJeff Lockhart
03/21/2024, 7:51 PMYoussef Shoaib [MOD]
03/21/2024, 8:23 PMinterface Summable<T> {
operator fun T.plus(other: T): T
}
object IntSummable: Summable<Int> { ... }
context(Summable<T>) fun List<T>.sum() = ...
// Usage
with(IntSummable) { myList.sum() }