Aaron Song
Aaron Song

Reputation: 41

How to access this in Kotlin sequence generator?

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

Answers (1)

broot
broot

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

Related Questions