Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert rxJava2's Observable to Completable?

I have Observable stream, and I want to convert it to Completable, how I could do that?

like image 714
Stepango Avatar asked Nov 03 '16 10:11

Stepango


People also ask

How do I convert Observable to maybe?

Unfortunately, there is no straightforward way to convert an Observable to Maybe (unless you are interested in just the firstElement ). You can convert it to Single first though and then to Maybe using toMaybe . This observable is only concerned about two things, if some action is executed or an error is encountered.

How do I extract an object from Observable?

You cannot 'extract' something from an observable. You get items from observable when you subscribe to them (if they emit any). Since the object you are returning is of type Observable, you can apply operators to transform your data to your linking.

How do you convert single to Observable?

If I understood correctly, you want to convert Single<List<Item>> into stream of Item2 objects, and be able to work with them sequentially. In this case, you need to transform list into observable that sequentially emits items using . toObservable(). flatMap(...) to change the type of the observable.

What is Completable RxJava?

Single and Completable are new types introduced exclusively at RxJava that represent reduced types of Observable , that have more concise API. Single represent Observable that emit single value or error. Completable represent Observable that emits no value, but only terminal events, either onError or onCompleted.


1 Answers

The fluent way is to use Observable.ignoreElements().

Observable.just(1, 2, 3) .ignoreElements() 

Convert it back via toObservable if needed.

like image 167
akarnokd Avatar answered Oct 10 '22 00:10

akarnokd