These are chat archives for ReactiveX/RxJava

24th
May 2016
Vadym
@dragantl
May 24 2016 23:22
Can anyone propose a more elegant way of keeping track of emission count for observable than below? I need to emit a structure along with its sequence counter so that it looks like so (it eventually gets serialized to json):
   {
      count: 5,
      data: {...}
   }
Observable<Data> dataObservable = DataProvider.getDataObservable();
// Should I use something like Observable.just(1).window(dataObservable).flatMap(window -> ...).scan(0, (sum, value) -> sum + value);
Observable<Integer> countObservable = dataObservable.map(data -> 1).scan(0, (sum, value) -> sum + value);

Observable<Structure> structureObservable = Observable.zip(dataObservable, countObservable, (data, count) -> new Structure(count, data));

structureObservable.subscribe(structure -> {
   ...
});