package io.reactivex.internal.operators.observable; import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.BiFunction; import io.reactivex.internal.disposables.DisposableHelper; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.functions.ObjectHelper; import io.reactivex.plugins.RxJavaPlugins; import java.util.Iterator; /* loaded from: classes2.dex */ public final class ObservableZipIterable extends Observable { final Observable a; final Iterable b; final BiFunction c; static final class ZipIterableObserver implements Observer, Disposable { final Observer a; final Iterator b; final BiFunction c; Disposable d; boolean e; ZipIterableObserver(Observer observer, Iterator it, BiFunction biFunction) { this.a = observer; this.b = it; this.c = biFunction; } void a(Throwable th) { this.e = true; this.d.dispose(); this.a.onError(th); } @Override // io.reactivex.disposables.Disposable public void dispose() { this.d.dispose(); } @Override // io.reactivex.Observer public void onComplete() { if (this.e) { return; } this.e = true; this.a.onComplete(); } @Override // io.reactivex.Observer public void onError(Throwable th) { if (this.e) { RxJavaPlugins.b(th); } else { this.e = true; this.a.onError(th); } } @Override // io.reactivex.Observer public void onNext(T t) { if (this.e) { return; } try { U next = this.b.next(); ObjectHelper.a(next, "The iterator returned a null value"); try { V apply = this.c.apply(t, next); ObjectHelper.a(apply, "The zipper function returned a null value"); this.a.onNext(apply); try { if (this.b.hasNext()) { return; } this.e = true; this.d.dispose(); this.a.onComplete(); } catch (Throwable th) { Exceptions.b(th); a(th); } } catch (Throwable th2) { Exceptions.b(th2); a(th2); } } catch (Throwable th3) { Exceptions.b(th3); a(th3); } } @Override // io.reactivex.Observer public void onSubscribe(Disposable disposable) { if (DisposableHelper.validate(this.d, disposable)) { this.d = disposable; this.a.onSubscribe(this); } } } public ObservableZipIterable(Observable observable, Iterable iterable, BiFunction biFunction) { this.a = observable; this.b = iterable; this.c = biFunction; } @Override // io.reactivex.Observable public void subscribeActual(Observer observer) { try { Iterator it = this.b.iterator(); ObjectHelper.a(it, "The iterator returned by other is null"); Iterator it2 = it; try { if (it2.hasNext()) { this.a.subscribe(new ZipIterableObserver(observer, it2, this.c)); } else { EmptyDisposable.complete(observer); } } catch (Throwable th) { Exceptions.b(th); EmptyDisposable.error(th, observer); } } catch (Throwable th2) { Exceptions.b(th2); EmptyDisposable.error(th2, observer); } } }