Using this inside an object expression inside an extension function


#1

There is a more elegant way to call this than ressing it to a variable?

public fun<T> Function1<Subscriber<in T>, Unit>.asObservable(): Observable<T> {   val v = this   return Observable.create(object:OnSubscribe<T> {   override fun call(t1: Subscriber<in T>?) {            v(t1!!)   }

  })!!
}


Cheers!


#2

Yes, you can use labels

public fun<T> Function1<Subscriber<in T>, Unit>.asObservable(): Observable<T> {
    return Observable.create(object:OnSubscribe<T> {
        override fun call(t1: Subscriber<in T>?) {
            this@asObservable(t1!!)
        }

  })!!
}

There is a link: http://confluence.jetbrains.com/display/Kotlin/This+expressions#Thisexpressions-Qualified


#3

Thanks