kotlin - RxJava how to group items of one list to Map<Key, List<Value>> -


i have class "cabinet" such structure:

class cabinet {    var title: string    var floor: int    var cabinetnumber: int } 

and class "tabs"

class tabs {    var floor: int    var cabinetlist: list<cabinet> } 

so of rxjava i'm trying create observable<list<tabs>>. firstly list of cabinet, have "cabinets" "tabs" structure.

fun getcabinets(): observable<list<tabs>> {    return getcabs()      //this metod returns list<cabinet>           .observeon(schedulers.io))           .filter { it.title != null }           ... ???  //there don't next 

i thought use "tomap" create collection map<floor: int, cabinetlist: list<cabinet>> don't know how make reqursively. please help

to put cabinets map utilize collectinto operator:

getcabs()     .filter { it.title != null }     .collectinto(mutablemapof<int, mutablelist<cabinet>>()) { map, cabinet ->         if(map.contains(cabinet.floor)) map[cabinet.floor]?.add(cabinet)         else map.put(cabinet.floor, mutablelistof(cabinet))      }      // here map<int, list<cabinet>> 

going further, map map list<tab> using flatmapiterable , set of map entries:

    .toobservable() // because collectinto returns single     .flatmapiterable { it.entries }     .map { tab(floor = it.key, cabinetlist = it.value) }     // here observable<list<tabs>> 

p.s. assume use rxjava2.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -