Combine Observable with second Observable which uses results from from the first one

Deadly 提交于 2020-01-02 05:23:21

问题


I have two methods returning Observable:

Observable<String> firstObservable();
Observable<String> secondObservable(String value);

For each result from the first Observable I get new instance of the second Observable. For each result from the second observable I would return object with combined results.

firstObservable ->  x----x----x----x----x
                     \    \    \    \    \
secondObservable ->   y(x)-y(x)-y(x)-y(x)-y(x)
                      \     \     \     \     \
result ->             {x,y}-{x,y}-{x,y}-{x,y}-{x,y}

How can this be done?


回答1:


There's an overloaded variant of flatMap, the second argument of which is the combining function that has access to the initial item and the one produced by the second observable:

firstObservable.flatMap(string -> secondObservable(string), (s, s2) -> s + s2);



来源:https://stackoverflow.com/questions/35292875/combine-observable-with-second-observable-which-uses-results-from-from-the-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!