Created
August 19, 2018 08:18
-
-
Save anitaa1990/2a1a7309b0a050ebd307bac3913428db 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
/* | |
* We create two Observables which emit an item evert second. | |
* We combine the two Observables using zip() operator. | |
* This combines the result of both operators together so we can | |
* perform some modifications to the results and emit them. | |
*/ | |
Observable<String> alphabets1 = Observable | |
.interval(1, TimeUnit.SECONDS).map(id -> "A" + id); | |
Observable<String> alphabets2 = Observable | |
.interval(1, TimeUnit.SECONDS).map(id -> "B" + id); | |
Observable.zip(alphabets1, alphabets2, new BiFunction<String, String, String>() { | |
@Override | |
public String apply(String s, String s2) { | |
return (s + " " + s2); | |
} | |
}) | |
.subscribe(new Observer<String>() { | |
@Override | |
public void onSubscribe(Disposable d) { | |
} | |
@Override | |
public void onNext(String s) { | |
System.out.println("onNext: " + s); | |
} | |
@Override | |
public void onError(Throwable e) { | |
} | |
@Override | |
public void onComplete() { | |
} | |
}); | |
Thread.sleep(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment