June 2017
Intermediate to advanced
400 pages
8h 44m
English
For a given Observable<T>, the startWith() operator allows you to insert a T emission that precedes all the other emissions. For instance, if we have an Observable<String>that emits items on a menu we want to print, we can use startWith() to append a title header first:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable<String> menu = Observable.just("Coffee", "Tea", "Espresso", "Latte"); //print menu menu.startWith("COFFEE SHOP MENU") .subscribe(System.out::println); }}
The output of the preceding code snippet is as follows:
COFFEE SHOP MENUCoffeeTeaEspressoLatte
If you want to start with more than one emission, use startWithArray() to accept varargs parameters. If we want ...
Read now
Unlock full access