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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Observable.just method


The just() method emits its parameter(s) as OnNext notifications, and after that, it emits an OnCompleted notification.

For example, one letter:

Observable.just('S').subscribe(System.out::println);

Or a sequence of letters:

Observable
  .just('R', 'x', 'J', 'a', 'v', 'a')
  .subscribe(
    System.out::print,
    System.err::println,
    System.out::println
  );

The first piece of code prints S and a new line, and the second prints the letters on a single line and adds a new line on completion. The method allows up to nine arbitrary values (objects of the same type) to be observed through reactive means. For example, say we have this simple User class:

public static class User {
  private final String forename;
  private final String lastname;
  public User(String forename, String lastname) {
    this.forename = forename;
    this.lastname = lastname;
  }
  public String getForename() {
    return this.forename;
  }
  public String getLastname() {
    return this.lastname...