RxJava - Creating Operators

We are now know what Obervable and we are able to declaratively massage data emitted upstream to produce a desired
result. Arguably, the set of Operators and the ability to transform, combine, and aggregate items in
such a way is one of the main reasons why RxJava is so powerful.
Now we will look into Operators and how to use operators with Observables

 

RxJava - Creating Operators

Below are the operators which are used to create Observable

Sr.No. Operator & Description
1

Create

Creates an Observable from scratch and allows observer method to call programmatically.

2

Defer

Do not create an Observable until an observer subscribes. Creates a fresh observable for each observer.

3

Empty/Never/Throw

Creates an Observable with limited behavior.

4

From

Converts an object/data structure into an Observable.

5

Interval

Creates an Observable emitting integers in sequence with a gap of specified time interval.

6

Just

Converts an object/data structure into an Observable to emit the same or same type of objects.

7

Range

Creates an Observable emitting integers in sequence of given range.

8

Repeat

Creates an Observable emitting integers in sequence repeatedly.

9

Start

Creates an Observable to emit the return value of a function.

10

Timer

Creates an Observable to emit a single item after given delay.

 

Examples

Observable.just

 Observable.just("Person1", "Person2", "Person3")
            .subscribe(s->System.out.println(s));

 

Observable.fromIterable

  List<String> cars = new ArrayList<>();
    cars.add("Mazda");
    cars.add("BMW");
    cars.add("Toyota");
    Observable.fromIterable(cars)
            .subscribe(s->System.out.println(s));

 

Observable.fromArray

    String[] cars = new String[] {"Sunday", "Monday", "Tueday"};
    Observable.fromArray(cars)
            .subscribe(s->System.out.println(s));

 

Observable.range

  Observable.range(0, 5)
            .subscribe(s->System.out.println(s));