Hi, I'm new to kotlin how can i return data from a...
# android
k
Hi, I'm new to kotlin how can i return data from an anonymous function?
Copy code
val flowable = mWebService?.getData
            flowable?.subscribeOn(<http://io.reactivex.schedulers.Schedulers.io|io.reactivex.schedulers.Schedulers.io>())
                    ?.subscribe({ response ->
                        Logger.i(TAG, "onNext $response")
                        return true //<------------ how do I return this
                    }, { throwable ->
                        Logger.i(TAG, "onError $throwable")
                    }, {
                        Logger.i(TAG, "onCompleted")
                    })
g
Just omit return, it's lambda and result of the last expression will be returned from lambda
m
And it is lambda expression
g
Also, all those nullable properties looks bad (a lot of question marks), better to avoid them if it's possible on this case. imho
r
I am afraid you can't do that. As your code is async. So it will not directly return value. You can omit subscribe. Than call flowable.subscribe { isSuccess -> } unless you make RxJava is not async. Another options is using couroutine.