● Makes dealing with concurrency easy ● Makes code a lot more concise and readable ● Encourages defensive programming and makes error handling easy ● Increases the level of abstraction Why consider RxJava?
What is RxJava? ● Java implementation of .NET’s Reactive Extensions ○ Specification for Functional Reactive Programming (FRP) ● Programming with asynchronous data streams ○ Not a new concept. Think: click events/handlers, event bus, etc. ○ Reactive part ● Can combine, create, filter, map, or transform any stream ○ Functional part
Observer ● Observer (aka the “subscriber”) subscribes to Observable ● Observers are notified of a new item through #onNext(...) ● Observers are notified when there sequence completes/fails through #onCompleted()/#onError()
Creating an Observable ● Create an Observable from item/s using #just(...) ● Create an Observable from an Iterable using #from(...) ● Create an Observable that emits items given an interval using #interval(...)
Operator ● Most powerful part about Observables is that you can transform them and perform functional style programming—map(), debounce(), filter(), etc. ● Transform Observable instances through Operators
Scheduling an Observable ● Specify a Scheduler where the Observable should operate using #subscribeOn(...), specify a Scheduler where the Observable should notify its observers using #observeOn(...)