Michał K Michał K -4 years ago 174
Android Question

Observable.just() which returns Unit in Kotlin

I have a piece of Observable which in the end either returns an error and retries or just returns onNext. I don't need anything in onNext, so this is just an

Observable<Unit>
.

Now the problem is that at the end of the chain I have to hit this onNext and I don't have anything other than good old
Observable.just()
. But I cannot return Observable.just(null) because it returns
Nothing?
, not
Unit
. I cannot return
Unit
, because it's not instantiable. Therefore I have
Observable.just(null).map{}
. It works, but looks ugly. Any idea for a better solution?

Answer Source

Use Observable.just(Unit). Unit itself is the single object of the type Unit.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download