RxJava 2,flatmap 的 resultSelector 参数会发生什么? [英] RxJava 2, what happen the resultSelector argument of flatmap?
问题描述
在 RxJava1 flatmap
中有一个重载方法,允许您保留源值并将其传递到流中.
In RxJava1 flatmap
had a overloaded method that allowed you to retain source values and pass it down the stream.
我从以下博文中获得了这些知识
I've gained this knowledge from the following blog post
然而,转向 RxJava2,我似乎找不到它.我检查了 Rx1 和 Rx2 的更改,但未列出.我想知道它是否仍然存在,但我可能没有找对地方.
However, moving to RxJava2, I cannot seem to find it. I checked the changes from Rx1 and Rx2 and it is not listed. I would like to know if it exists still but I am perhaps not looking in the right place.
顺便说一下,我使用的是 Single
.
I am using a Single
by the way.
推荐答案
我不认为 Single
曾经支持过这个操作符和 Observable
/Flowable
运算符仍然存在.您可以通过映射内部源的结果来完成此行为:
I don't think Single
ever supported this operator and the Observable
/Flowable
operators are still there. You can accomplish this behavior by mapping the result of the inner source:
source.flatMap(originalValue ->
createInnerSource(originalValue)
.map(innerValue -> process(originalValue, innerValue))
)
map
的 lambda 将为您捕获 originalValue
.
The lambda of the map
will capture the originalValue
for you.
这篇关于RxJava 2,flatmap 的 resultSelector 参数会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!