Skip to content

Instantly share code, notes, and snippets.

@RaviH
Created October 28, 2015 20:53
Show Gist options
  • Save RaviH/707603238e9040091872 to your computer and use it in GitHub Desktop.
Save RaviH/707603238e9040091872 to your computer and use it in GitHub Desktop.
package com.charter.aesd.deviceactivation.middle.rest;
import rx.Observable;
import java.util.Optional;
/**
* Created by rhasija on 10/28/15.
*/
public class ObservableTest {
public static void main(String[] args) {
final Observable<Optional<Integer>> observable1 = Observable.just(Optional.of(1));
final Observable<Optional<Integer>> observable2 = Observable.just(Optional.of(2));
final Observable<Optional<Integer>> observable3 = Observable.just(Optional.of(3));
final Optional<Integer> single = observable1.flatMap(integer -> {
if (integer.get() != 1) {
return Observable.just(integer);
} else {
return observable2;
}
}).flatMap(integer -> {
if (integer.get() != 2) {
return Observable.just(integer);
} else {
return observable3;
}
}).toBlocking().single();
if (single.get() == 3) {
System.out.println("PASSED");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment