RxJava Tutorial on RxJava Mathematical Operators

following are the operators which operates on entire items emitted by an observable.

sr.no. operator & description
1

average

evaluates averages of all items and emit the result.

2

concat

emits all items from multiple observable without interleaving.

3

count

counts all items and emit the result.

4

max

evaluates max valued item of all items and emit the result.

5

min

evaluates min valued item of all items and emit the result.

6

reduce

apply a function on each item and return the result.

7

sum

evaluates sum of all items and emit the result.

mathematical operator example

create the following java program using any editor of your choice in, say, c:\> rxjava.

observabletester.java

import io.reactivex.observable;
//using concat operator to operate on multiple observables
public class observabletester  {
   public static void main(string[] args)  throws interruptedexception {    
      integer[] numbers = { 1, 2, 3, 4, 5, 6};
      string[] letters = {"a", "b", "c", "d", "e", "f", "g"};
      final stringbuilder result = new stringbuilder();
      observable<string> observable1 = observable.fromarray(letters);
      observable<integer> observable2 = observable.fromarray(numbers);
      observable.concat(observable1, observable2)
         .subscribe( letter -> result.append(letter));
      system.out.println(result);
   }
}

verify the result

compile the class using javac compiler as follows −

c:\rxjava>javac observabletester.java

now run the observabletester as follows −

c:\rxjava>java observabletester

it should produce the following output −

abcdefg123456