Reputation: 2053
I have a Flowable object Flowable<Data>
based on the Data property I need to continue the chain either using flatmap
or switchmap
operator and where I will call the method which returns 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>; })
Here, after combineLatest, where I have Flowable I want to decide based on a property to call either flatmap() or switchmap(). Wondering how can I continue.
One thing that came to my mind is following, to have the AtomicBoolean and then I can do the following pass to compose() but I am not sure if this is a right approach?
.compose(new SwitchMapWithFlatMap(state.get()))
Upvotes: 1
Views: 180
Reputation: 69997
You could just have the combineLatest
reference and apply your choice of operator conditionally:
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 -> ...);
});
Upvotes: 1