Jonathan Ellis
06/03/2022, 3:15 PMvar current: Body? = this@Body
but the compiler doesn't like thatJoffrey
06/03/2022, 3:15 PMthis@iterator
instead (the name function that has the receiver you want to refer to)Jonathan Ellis
06/03/2022, 3:16 PMJoffrey
06/03/2022, 3:17 PMthis
you're trying to access".Jonathan Ellis
06/03/2022, 3:18 PMJoffrey
06/03/2022, 3:18 PMChris Lee
06/03/2022, 3:19 PMfunction/label
Jonathan Ellis
06/03/2022, 6:08 PMYoussef Shoaib [MOD]
06/03/2022, 7:28 PMfun <A> A.given(): A = this
usage:
operator fun Body.iterator(): Iterator<Body> {
return object : Iterator<Body> {
var current: Body? = given<Body>()
...
}
}
(This really comes in handy with Context Receivers because it allows differentiating between a List<Int>
and a List<String>
for instance)