Created
January 4, 2017 11:30
-
-
Save kevalpatel2106/5047be2bee9f59cc151c31cfd17c83b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Class that combines both data streams | |
class ZipObject { | |
int number; | |
String alphabet; | |
} | |
Observable<Integer> observable1 = Observable.from(new Integer[]{1, 2, 3, 4, 5}); //Emits integers | |
Observable<String> observable2 = Observable.from(new String[]{"A", "B", "C", "D", "F"}); //Emits alphabets | |
Observable<ZipObject> observable = Observable.zip(observable1, observable2, | |
//Function that define how to zip outputs of both the stream into single object. | |
new Func2<Integer, String, ZipObject>() { | |
@Override | |
public ZipObject call(Integer integer, String s) { | |
ZipObject zipObject = new ZipObject(); | |
zipObject.alphabet = s; | |
zipObject.number = integer; | |
return zipObject; | |
} | |
}); | |
observable | |
.subscribeOn(Schedulers.newThread()) | |
.observeOn(Schedulers.io()) | |
.subscribe(new Action1<ZipObject>() { | |
@Override | |
public void call(ZipObject zipObject) { | |
Log.d("Observer", "Output:" + zipObject.number + " " + zipObject.alphabet); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment