orca
06/07/2024, 7:55 AMabstract class Thing {
    fun someFunctionWeWant(): String {
        // ...
        return "hello!"
    }
}
interface IThingAdjacentInterface : Thing {
    
    val someProp: String
    fun doSomething() {
        
        val data = someFunctionWeWant()
        
        // ...
        
    }
}
class Something : Thing(), IThingAdjacentInterface {
    override val someProp = "hi!"
}
fun processSomeStuff() {
    
    val items: List<IThingAdjacentInterface> = listOf(Something())
    // ...
    
    items.forEach { 
        it.doSomething()
        someMoreStuff(it.someProp)
    }
    
}interface IThingAdjacentInterface {
    
    val someProp: String
    context(Thing)
    fun doSomething() {
        
        val data = someFunctionWeWant()
        
        // ...
        
    }
}
// ...
fun processSomeStuff() {
    val items: List<Thing> = listOf(Something())
    // ...
    items
        .forEach {
            if (it is IThingAdjacentInterface) {
                // `run` means its context receiver is... itself, compiler is happy with this.
                it.run { doSomething() }
            }
        }
}context(Thing)
interface IThingAdjacentInterfaceThingThingThingSam
06/07/2024, 7:59 AMinterface Thing {
  fun someFunctionWeWant(): String
}
class ConcreteThing : Thing {
  override fun someFunctionWeWant(): String = "hello!"
}
interface IThingAdjacentInterface : Thing {
  val someProp: String
  fun doSomething() {
    val data = someFunctionWeWant()
    // ...
  }
}
class Something : IThingAdjacentInterface, Thing by ConcreteThing() {
  override val someProp = "hi!"
}Sam
06/07/2024, 8:01 AMSam
06/07/2024, 8:03 AMIThingAdjacentInterfaceYoussef Shoaib [MOD]
06/07/2024, 10:09 AMinterface IThingAdjacentInterface {
  val asThing: Thing
  ...
  fun doSomething() {
    val data = asThing.someFunctionWeWant()
  }
}