These are chat archives for ReactiveX/RxJava

5th
Jan 2016
Josh Durbin
@joshdurbin
Jan 05 2016 21:17
Is it possible to count emitted elements as they flow through a stream, and manipulate the emitted items to include the counter?
Dorus
@Dorus
Jan 05 2016 21:17
Isn't that a default overload for map?
Josh Durbin
@joshdurbin
Jan 05 2016 21:18
For example, if I have a stream that returns Observable<Person>, perhaps use a map to then modify the stream return type to return a tuple of Person, counter, or perhaps a whole new object, Observable<CountedPerson> or something...
Essentially I just want to count the emitted items and then return that count WITH the emitted item.
Dorus
@Dorus
Jan 05 2016 21:22
Had exactly that question on RxJS today, there we could do map((x, idx) => {el: x, idx: idx}). I'm trying to find out if RxJava has a similar overload on map.
Actually that was after a groupBy. Also cool
Anyway the alternative is Scan
scan(tuple2.create(null, 0), (tup, item) -> tuple2.create(item, tup.value2() + 1))
Josh Durbin
@joshdurbin
Jan 05 2016 21:36
Ohhh alright I'll check it out. Thanks!