Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rxjava-当链接观察到如何取回其他类型的流(返回值)而不是当前流?_Java_Rx Java - Fatal编程技术网

Rxjava-当链接观察到如何取回其他类型的流(返回值)而不是当前流?

Rxjava-当链接观察到如何取回其他类型的流(返回值)而不是当前流?,java,rx-java,Java,Rx Java,我执行了一个可观察调用,在它完成后,它立即链接到另一个可观察调用以将结果存储到数据库中。它看起来很简单: protected Observable<List<Long>> buildUseCaseObservable() { return mDataRepo.fetchCountries().flatMap(new Function<List<CountryModel>, ObservableSource<List<

我执行了一个可观察调用,在它完成后,它立即链接到另一个可观察调用以将结果存储到数据库中。它看起来很简单:

    protected Observable<List<Long>> buildUseCaseObservable() {
         return mDataRepo.fetchCountries().flatMap(new Function<List<CountryModel>, ObservableSource<List<Long>>>() {
             @Override
             public ObservableSource<List<Long>> apply(@NonNull List<CountryModel> countryModels) throws Exception {
                 return mDataRepo.storeCountries(countryModels);
             }
         });
     }
受保护的可观察buildUseCaseObservable(){
返回mDataRepo.fetchCountries().flatMap(新函数(){
@凌驾
public observesource apply(@NonNull List countryModels)引发异常{
返回mDataRepo.storeCountries(countryModels);
}
});
}
现在我的问题是我希望订阅者返回第一个可观察到的结果。所以我喜欢
订户要取回
,而不是现在取回的
。有什么办法可以这样做吗?不确定concat是否有帮助?

事实上,是的,您可以将
flatMap()
变量与
resultSelector
一起使用,您可以从
flatMap()
的输入和输出中选择或组合,并且在您的情况下,只返回获取的国家,而不是ID:

protected Observable<List<CountryModel>> buildUseCaseObservable() {
    Repo mDataRepo = new Repo();
    return mDataRepo.fetchCountries()
            .flatMap(new Function<List<CountryModel>, ObservableSource<List<Long>>>() {
                @Override
                public ObservableSource<List<Long>> apply(
                        @android.support.annotation.NonNull List<CountryModel> countryModels) throws Exception {
                    return mDataRepo.storeCountries(countryModels);
                }
            }, new BiFunction<List<CountryModel>, List<Long>, List<CountryModel>>() {
                @Override
                public List<CountryModel> apply(List<CountryModel> countryModels,
                                                List<Long> longs) throws Exception {
                    return countryModels;
                }
            });
}
受保护的可观察buildUseCaseObservable(){
Repo mDataRepo=新的Repo();
返回mDataRepo.fetchCountries()
.flatMap(新函数(){
@凌驾
公共可观测资源应用(
@android.support.annotation.NonNull列表(模型)引发异常{
返回mDataRepo.storeCountries(countryModels);
}
},新的双功能(){
@凌驾
公共列表适用(列表国家/地区型号,
列表长度)引发异常{
回归模型;
}
});
}

Android studio中的Ctrl-c Ctrl-v?您应该知道,有时@DouglasMesquita无法正确转换,请参见以下示例: