android - What is the way for having a list through rxjava? -
i bit new rxjava. trying have list on rxjava iterating on result. tried operator tolist() not work out. following working fine. however, wonder if there better way reactive perspective?
db.loaddata().map(new func1<realmresults<data>, list<string>>() { @override public list<string> call(realmresults<data> datas) { list<string> companies = new arraylist<string>(5); (company company : datas.get(0).getcompanies()) { companies.add(company.getname()); } return companies; } }).subscribe(new action1<list<string>>() { @override public void call(list<string> strings) { showcompanydialog(strings); } });
so (pseudocode don't know object types have):
db.loaddata() .map(new func1<realmresults<data>, list<company>>() ) { public list<company> call(realmresults<data> datas) { return datas.get(0).getcompanies(); } }).flatmap(new func1<list<company>, observable<company>>() { @override public observable<company> call(list<company> companies) { return observable.from(companies); } }.map(new func1<company, string>() { public stringcall(company company) { return company.getname(); } }).tolist();
that means:
- get results database
- get companies realmresult
- split companies
- get name of each company
- concatenate results
list<string>
Comments
Post a Comment