I have got Observable<Rates>
and Rate is just a simple object:
Rate(val value:String){}
Rates(val rates: List<Rate>)
and i wanna change that Observable<Rates>
into Observable<HashMap<String,Long>
.
so for example for rates Rates(arrayOf(Rate("1"),Rate("2"), Rate("3"),Rate("3"), Rate("2"),Rate("2")))
i expect result:
(1 -> 1)
(2 -> 3)
(3 -> 2)
(4 -> 0)
(5 -> 0)
I start creating something like that :
service.getRates()
.flatMap {it-> Observable.from(it.rates) }
.filter { !it.value.isNullOrEmpty() }
.groupBy {it -> it.value}
.collect({ HashMap<String,Long>()}, { b, t -> b.put(t.key, t.count???)}
but I am stuck here and i do not know count all values? and i do not know how to add empty values (0) if there is no 5 of 4. Is there any way to do this using rx?