I have couple of api calls to make (sequentially, asynchronously) and some of them returns lists. My api interface is given below.
@GET(\"/users/settings\")
Obse
RxJava has added flatMapIterable
. So you don't need flattenList
now. E.g.,
Observable<UserWrapper> o =
getUserSettings()
.doOnNext(this::saveUser)
.flatMap(user -> getItems(user.getUserName())
.flatMapIterable(items -> items)
.flatMap(item -> getItemInfo(item.getId()))
.doOnNext(this::saveItem)
.toList()
.map(ignored -> user))
.flatMap(user -> getFriends(user.getUserName())
.flatMapIterable(friends -> friends)
.doOnNext(this::saveFriend)
.toList()
.map(ignored -> user)
);
o.subscribe(...);