Youssef Shoaib [MOD]
02/22/2024, 12:41 PMoperator fun componentN(i: Int)
that would generalise component1
, component2
etc? Or perhaps get
should serve that purpose if it has one Int
argumentephemient
02/22/2024, 12:53 PMKlitos Kyriacou
02/22/2024, 1:53 PM@Destructurable
MyClass {
fun component(index: Int) = TODO() // generates componentN() functions for 1-based index
operator fun get(index: Int) = TODO() // generates componentN() functions for 0-based index if fun component() is not defined
}
Klitos Kyriacou
02/22/2024, 1:53 PMephemient
02/22/2024, 2:00 PMtypeclass Indexed<E> {
operator fun get(index: Int): E]
}
operator fun <E> Indexed<E>.component1(): E = get(0)
operator fun <E> Indexed<E>.component2(): E = get(1)
// etc.
would "just work" for existing types. I don't think it'll happen though