傳遞數據在rxjava 1有可觀察過這種方法flatmapRxjava2通過flatMap
public final Observable flatMap(Func1 collectionSelector, Func2 resultSelector)
這讓你傳遞/初始結果結合到flatmap訂戶。
如何才能達到與rxjava2相同的結果?
我有一個發射A的單元,我需要基於A得到B,然後同時使用A和B來執行一個動作。
傳遞數據在rxjava 1有可觀察過這種方法flatmapRxjava2通過flatMap
public final Observable flatMap(Func1 collectionSelector, Func2 resultSelector)
這讓你傳遞/初始結果結合到flatmap訂戶。
如何才能達到與rxjava2相同的結果?
我有一個發射A的單元,我需要基於A得到B,然後同時使用A和B來執行一個動作。
您對RxJava2同樣的方法,無論是在Observable和Flowable,
但是,在這兩個RxJava1和2,對於Single
沒有這樣的操作,您可以將Single
to Observable
然後再應用此運營。
你嘗試CombineLatest(http://reactivex.io/documentation/operators/combinelatest.html)
基本上可以發射A和B,然後基於所述函數結果返回另一個目的:
RXJava1
Observable
.combineLatest([Add here your A observable],
[Add here your B observable],
new Func2<A, B, Result>() {
@Override
public Result call(A a, B b) {
//Do your stuff here combining both results and return the result expected
}
})
RXJava2
Observable
.combineLatest([Add here your A observable],
[Add here your B observable],
new BiFunction<A, B, Result>() {
@Override
public Result apply(A a, B b) throws Exception {
//Do your stuff here combining both results and return the result expected
}
})