Skip to content

Instantly share code, notes, and snippets.

@jpetitto
Last active November 18, 2015 19:55
Show Gist options
  • Save jpetitto/2614b047ebe00f5669c3 to your computer and use it in GitHub Desktop.
Save jpetitto/2614b047ebe00f5669c3 to your computer and use it in GitHub Desktop.
RxJava "groupBy" Operator
odd: 1
even: 2
odd: 3
even: 4
odd: 5
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