Reputation: 41
I'm using sequence to produce a Iterable<T>
as a member function in Kotlin, but in the sequence lambda this
refers to SequenceScope<T>
. I want to access this
, how do I do this?
class A{
fun getSomething() = sequence {
yield(this)// this means Scope, I want to return this object
}
}
Upvotes: 1
Views: 224
Reputation: 28470
You need to reference the outer scope with: this@A
. This is explained here: https://kotlinlang.org/docs/this-expressions.html#qualified-this
Upvotes: 1