Is there any way of counting the amount of elements that have already been processed in a stream in RxAndroid?
I am having something like that:
Observable.fromArray(new String[]{"these", "are", "my", "values", "."})
.map(s -> doSomeCoolStuff(s))
// ...
.subscribe(amountOfProcessedItems -> Log.d("test", "" + amountOfProcessedItems));
And I am looking for something so that my output would look like 1 2 3 4 5
, basically after each item count the amount of items that have already been emitted.
mapWithIndex
method specifically to do what you ask. Just replace yourmap
call. – AvonmapWithIndex
isn't part of RxJava: it's in github.com/davidmoten/rxjava-extras – Sage