Advertisement
sivakfil

Concat-first

Apr 6th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package ass.excercises.cvi8.demo1;
  2.  
  3. import io.reactivex.Observable;
  4.  
  5. public class ConcatFirst {
  6.    
  7.     public static void main(String[] args) {
  8.         Observable.just("a", "b")
  9.         .flatMap(item ->
  10.             Observable.concat(
  11.                     Observable.just(item + "1"),
  12.                     Observable.just(item + "2")     // this is never called
  13.             )
  14.             .first("N/A")   // here you can return implementation of IResponse that represents some kind of error
  15.             .toObservable()
  16.         )
  17.         .forEach(System.out::println);
  18.        
  19.         System.out.println("=====");
  20.        
  21.         Observable.just("c", "d")
  22.         .flatMap(item ->
  23.             Observable.concat(
  24.                     Observable.empty(),         // simulates cache that didn't return anything
  25.                     Observable.just(item + "2") // now it's called
  26.             )
  27.             .first("N/A")
  28.             .toObservable()
  29.         )
  30.         .forEach(System.out::println);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement