Created
October 28, 2015 20:53
-
-
Save RaviH/707603238e9040091872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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