我有一个基于Data属性的Flowable对象Flowable<Data>
,我需要使用flatmap
或switchmap
运算符继续链,并在其中调用返回Flowable的方法。
Data(a:boolean, str:String)
return Flowable.defer(
() -> {
final int[] indices = new int[3];
//AtomicBoolean state = new AtomicBoolean(false);
return Flowable.combineLatest(a,b,c,()->{
return Flowable<Data>; })
这里,在combineLatest之后,在我有Flowable的地方,我想根据一个属性来决定调用flatmap((或switchmap((。想知道我该怎么继续。
我想到的一件事是,使用AtomicBoolean,然后我可以对compose((进行以下操作,但我不确定这是否是正确的方法?
.compose(new SwitchMapWithFlatMap(state.get()))
您可以只使用combineLatest
引用并有条件地应用您选择的运算符:
return Flowable.defer(() -> {
final int[] indices = new int[3];
//AtomicBoolean state = new AtomicBoolean(false);
Flowable<Data> f = Flowable.combineLatest(a, b, c, (x, y, z) -> {
return Flowable<Data>;
});
if (state.get()) {
return f.flatMap(w -> ... );
}
return f.switchMap(w -> ...);
});