说我也有那些课
class Event {
int id;
String name;
List<Integer> facilityIds;
List<Facility> facilities; // Empty, the one I need to load
}
class Facility {
int id;
String name;
}
目标:打印出每个事件及其设施的名称。
约束:RxJava2,Facilities 只能一一加载(getFacility(facilityId)
)
从一个Observable<Event>
,我无法找到加载设施并将它们设置回各自事件的方法。
基本上我在想这样的事情:
Observable<Event> events;
events
.map(Event::getFacilityIds)
.flatMap(Observable::fromIterable)
.map(facilityId -> service.getFacility(facilityId))
. // somehow get the event reference and
// so some event.addFacility() or something similar
然后我失明了,无法找到将它们链接回事件的方法。我也考虑过使用zip
,它可能是一个解决方案,但我没有找到一种方法来保留和事件引用,以便以后为它们设置设施。
什么是反应式的方法?任何提示将不胜感激。