Last active
November 18, 2015 19:55
-
-
Save jpetitto/2614b047ebe00f5669c3 to your computer and use it in GitHub Desktop.
RxJava "groupBy" Operator
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
odd: 1 | |
even: 2 | |
odd: 3 | |
even: 4 | |
odd: 5 |
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
Observable.just(1, 2, 3, 4, 5) | |
.groupBy(i -> i % 2 == 0 ? "even" : "odd") | |
.subscribe(obs -> { | |
if (obs.getKey().equals("even")) { | |
obs.subscribe(i -> System.out.println("even: " + i)); | |
} else { | |
obs.subscribe(i -> System.out.println("odd: " + i)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment