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) {
  observable.subscribe(
    (v) -> System.out.println(name + " : " + v),
    (e) -> {
      System.err.println("Error from " + name + ":");
      System.err.println(e.getMessage());
    },
    () -> 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 ...

Get Learning Reactive Programming with Java 8 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.