Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anitaa1990/dc168b63a0a9839cf240e911a8bee0e9 to your computer and use it in GitHub Desktop.
Save anitaa1990/dc168b63a0a9839cf240e911a8bee0e9 to your computer and use it in GitHub Desktop.
/*
* Step 1: Create an observable that emits an integer
* from 1 to 5. Each item is squared by itself before it is
* emitted.
* */
Observable<Integer> observable = Observable.range(1, 5)
.subscribeOn(Schedulers.io())
.map(integer -> {
System.out.println(String.format("Squaring %d with itself", integer));
return integer * integer;
});
/*
* Step 2: We are subscribing two subscribers to the Observable.
* */
observable.subscribe(s -> System.out.println("subscriber one: " + s));
observable.subscribe(s -> System.out.println("subscriber two: " + s));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment