I'm zipping multiple Observables together and then transforming them in a way that results in an Observable:
final Observable<Observable<M>> result = Observable.zip(obs1, obs2, transformFunc);
What I'd like to be able to do is:
final Observable<M> result = Observable.flatZip(obs1, obs2, transformFunc);
What's the cleanest way to do this, given flatZip doesn't exist (maybe I should submit one). At the moment I'm having to flatMap the result in on itself.
public class RxHelper {
public static <T1, T2, R> Observable<R> flatZip(Observable<? extends T1> o1, Observable<? extends T2> o2, final Func2<? super T1, ? super T2, Observable<? extends R>> zipFunction) {
return Observable.merge(Observable.zip(o1, o2, zipFunction));
}
public static <T1, T2, T3, R> Observable<R> flatZip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Func3<? super T1, ? super T2, ? super T3, Observable<? extends R>> zipFunction) {
return Observable.merge(Observable.zip(o1, o2, o3, zipFunction));
}
public static <T1, T2, T3, T4, R> Observable<R> flatZip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Func4<? super T1, ? super T2, ? super T3, ? super T4, Observable<? extends R>> zipFunction) {
return Observable.merge(Observable.zip(o1, o2, o3, o4, zipFunction));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With