Skip to content

Instantly share code, notes, and snippets.

@yelinaung
Created November 18, 2014 15:03
Show Gist options
  • Select an option

  • Save yelinaung/297ae92c4bcbe5089a02 to your computer and use it in GitHub Desktop.

Select an option

Save yelinaung/297ae92c4bcbe5089a02 to your computer and use it in GitHub Desktop.
public static void main(String[] args) {
// odd/even into lists of 10
Observable.range(1, 100).groupBy(n -> n % 2 == 0)
.flatMap(g -> {
return g.take(10).toList();
}).forEach(System.out::println);
}
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
[21, 23, 25, 27, 29, 31, 33, 35, 37, 39]
[22, 24, 26, 28, 30, 32, 34, 36, 38, 40]
[41, 43, 45, 47, 49, 51, 53, 55, 57, 59]
[42, 44, 46, 48, 50, 52, 54, 56, 58, 60]
[61, 63, 65, 67, 69, 71, 73, 75, 77, 79]
[62, 64, 66, 68, 70, 72, 74, 76, 78, 80]
[81, 83, 85, 87, 89, 91, 93, 95, 97, 99]
[82, 84, 86, 88, 90, 92, 94, 96, 98, 100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment