您可以將flatMap映射到另一個Observable,然後使用Observable.from(List)(請參閱http://reactivex.io/documentation/operators/from.html),該列表中的每個值都會爲onNext發出onNext。那是你在找什麼?
final List<String> listString = new ArrayList<>();
listString.add("AAAA");
listString.add("BBBB");
listString.add("CCCC");
Observable.just(listString)
.flatMap(new Func1<List<String>, Observable<String>>() {
@Override
public Observable<String> call(List<String> strings) {
Log.d("FLAT MAP", "call: " + strings);
return Observable.from(strings);
}
})
.map(new Func1<String, String>() {
@Override
public String call(String s) {
Log.d("MAP", "call: " + s);
return s;
}
})
.subscribe(new Action1<String>() {
@Override
public void call(String s) {
Log.d("SUBSCRIBER", "call: " + s);
}
});
輸出記錄
FLAT MAP: call: [AAAA, BBBB, CCCC]
MAP: call: AAAA
SUBSCRIBER: call: AAAA
MAP: call: BBBB
SUBSCRIBER: call: BBBB
MAP: call: CCCC
SUBSCRIBER: call: CCCC