如何从第一个可观察的

时间:2017-03-09 15:05:42

标签: android rx-java kotlin

我有这样的流程

        Observable.fromIterable(configuration.symbols) // list of data (for ex. 0, 1, 2, 3)
                    .subscribeOn(Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .flatMap {
api.anotherCall(
                                symbol = it) // emitted value 
                                .subscribeOn(Schedulers.newThread())
                                .observeOn(AndroidSchedulers.mainThread())
                    }
                    .subscribe { res ->
                        {
                            Ln.i(res) // result, but it would be perfect to know this data + symbol as a second param
                        }
                    }

感谢您的帮助

ps Kotlin语法

1 个答案:

答案 0 :(得分:0)

您必须使用flatMap以外的其他内容,例如zipdoc)。
使用zip,两个可观察量将被两个两个组合。

或者您可以继续使用flatMap,但在第二个可观察对象上添加map,如:

api.anotherCall(symbol = it) // emitted value 
    .map { secondValue -> it to secondValue }
    .subscribeOn(Schedulers.newThread())
    .observeOn(AndroidSchedulers.mainThread())

然后结束观察者将收到Pair<>

相关问题