I have a queue of items that will send once the server is reachable:
val queueHistory: Observable<QueuedItem>
A QueuedItem is:
data class QueuedItem(val item: Item, val sent: Boolean = false)
The queueHistory never completes, it just records when an item is being queued to be sent onNext(QueuedItem(item1, false)
, and then later records it was sent onNext(QueuedItem(item1, true)
.
What I want to do is get a current count of how many unsent items there are.
The main source of my trouble is due to the list not completing, I was initially thinking of using collect
but that needs a completed list.
I was playing around with using scan
with something like
queueHistory.scan { items: ScannedItems, item -> ScannedItems(arrayOf(*items, item), 0) }
Where I could keep the current list of items I have encountered so far, but scan wants everything to be the same type.
Another idea I had was
queueHistory
.groupBy { it.item }
.flatMapSingle { it.toList() }
.map { it.size % 2 }
But toList() needs a finite list.
Any ideas would be appreciated!