@Test public void advancedBatchingGrouping() { StepVerifier.create( Flux.just(1, 3, 5, 2, 4, 6, 11, 12, 13) .groupBy(i -> i % 2 == 0 ? "even" : "odd") .concatMap(g -> g.defaultIfEmpty(-1) //if empty groups, show them .map(String::valueOf) //map to string .startWith(g.key())) //start with the group's key ) .expectNext("odd", "1", "3", "5", "11", "13") .expectNext("even", "2", "4", "6", "12") .verifyComplete(); }