Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 542
Michał Klimczak Avatar asked Mar 01 '17 13:03

Michał Klimczak


People also ask

Which package provides observables in Kotlin?

Delegates. observable() is another built-in delegate of the Kotlin Standard Library.

What is a disposable Kotlin?

A Disposable is a stream or a link between an Observable and an Observer . A quick check of the documentation shows that it has two main methods, dispose() and isDisposed() .


1 Answers

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

like image 183
hotkey Avatar answered Oct 17 '22 22:10

hotkey