Earlier, we introduced a mechanism to skip duplicate entries from the financial stock updates that rely on .groupBy(). However, now it won't work because the distinctUntilChanged() block will get destroyed each time the .switchMap() block receives a new value and thus the last received entry will be lost.
The fix is quite simple. Consider this code:
.groupBy(stockUpdate -> stockUpdate.getStockSymbol())
.flatMap(groupObservable -> groupObservable.distinctUntilChanged())
It has to be moved outside the .merge():
Observable.merge(
...
)
.groupBy(stockUpdate -> stockUpdate.getStockSymbol())
.flatMap(groupObservable ->
groupObservable.distinctUntilChanged())
.compose(bindUntilEvent(ActivityEvent.DESTROY))
.subscribeOn(Schedulers.io())
This way, the .switchMap() block changes won't impact the last saved value, and it will successfully keep removing the duplicate entries as before.