Working on updating my app from RxJava2 to RxJava3. I know there are some updates to how groupBy works from reading the documentation, but I’m having trouble understanding why I’m seeing this behaviour. I have sections of code using groupBy that are now emitting individual GroupedFlowables for each item even when the keys match, instead of grouping the emissions under matched GroupedFlowables for the same key.
I’ve narrowed it down to a repeatable test:
fun runTest() {
val eventDTOFlowable = Flowable.just(
"item1",
"item2",
"item3",
"item4",
"item5",
"item6"
)
val groupedFlowables = eventDTOFlowable.groupBy { _ -> 1 }.cache().toList().blockingGet()
output = groupedFlowables.toString()
}
You can see in the breakpoint output (image below) that groupedFlowables
evaluates to a list of each flowable, each with a key of 1
, instead of grouping all the flowables under the a single GroupedFlowable with a key of 1. This was working on RxJava2, and checking the Rx groupBy docs I would expect it to do that, but it’s not anymore on RxJava3.
Breakpoint output of groupedFlowables
More likely is that my understanding of the changes to groupBy in rxjava3 is wrong, but any clarification is welcome.
Gwarglemar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2