我有一个方法返回
Single<List<Item>>
,遍历列表的唯一方法是
flattenAsObservable()
:
getListOfItems()
.flattenAsObservable {items -> items}
.flatMapSingle { item ->
doSomethingWith(item)
}
在
doSomethingWith(item)
我更新了
item
数据库中的对象。
现在,我想“统计”数据库中更新的项目,如果它们是n,则执行另一个更新。
我在找类似的东西:
getListOfItems()
.flattenAsObservable { items -> items }
.flatMapSingle { item ->
doSomethingWith(item)
}
.flatMapSingle { items -> items } // I can't access items here, obviously.
// I think I need another call to
// getListOfItems() and then filter(),
// but don't know how to do that.
.filter{ items.size() == X }
.flatMapSingle {
doSomething()
}