Book Image

Learning Reactive Programming with Java 8

By : Nickolay Tzvetinov
Book Image

Learning Reactive Programming with Java 8

By: Nickolay Tzvetinov

Overview of this book

Table of Contents (15 chapters)
Learning Reactive Programming with Java 8
About the Author
About the Reviewers

Other Observable factory methods

Here, we will inspect a few methods that can be used in combination with transforming operators such as flatMap or combining operators such as .zip file (more about this in the next chapter).

In order to examine their results, we will use the following method for creating subscriptions:

void subscribePrint(Observable<T> observable, String name) {
    (v) -> System.out.println(name + " : " + v),
    (e) -> {
      System.err.println("Error from " + name + ":");
    () -> System.out.println(name + " ended!")

The idea of the preceding method is to subscribe to an Observable instance and label it with a name. On OnNext, it prints the value prefixed with the name; on OnError, it prints the error together with the name; and on OnCompleted, it prints 'ended!' prefixed with the name. This helps us debug the results.


The source code of the preceding method can be found at...