following are the operators which are used to transform an item emitted from an observable.
sr.no. | operator & description |
---|---|
1 |
buffer gathers items from observable into bundles periodically and then emit the bundles rather than items. |
2 |
flatmap used in nested observables. transforms items into observables. then flatten the items into single observable. |
3 |
groupby divide an observable into set of observables organized by key to emit different group of items. |
4 |
map apply a function to each emitted item to transform it. |
5 |
scan apply a function to each emitted item, sequentially and then emit the successive value. |
6 |
window gathers items from observable into observable windows periodically and then emit the windows rather than items. |
transforming operator example
create the following java program using any editor of your choice in, say, c:\> rxjava.
observabletester.java
import io.reactivex.observable; //using map operator to transform an observable public class observabletester { public static void main(string[] args) { string[] letters = {"a", "b", "c", "d", "e", "f", "g"}; final stringbuilder result = new stringbuilder(); observable<string> observable = observable.fromarray(letters); observable .map(string::touppercase) .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 −
abcdefg