RxJava in Action

Get an overview of how things work in RxJava.

Sample RxJava code

Let’s take a look at some RxJava in action:

Press + to interact
Observable<Car> carsObservable = getBestSellingCarsObservable();
carsObservable.subscribeOn(Schedulers.io())
.filter(car -> car.type == Car.Type.ALL_ELECTRIC)
.filter(car -> car.price < 90000)
.map(car -> car.year + " " + car.make + " " + car.model)
.distinct()
.take(5)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::updateUi);

The above code will get the top 5 sub-$90,000 electric cars and then update the UI with that data.

There’s a lot going on here, so let’s see how it does this line-by-line:

  • Line 1: It all starts with our ...