package io.reactivex.internal.operators.observable; import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.functions.BiPredicate; import io.reactivex.functions.Function; import io.reactivex.internal.observers.BasicFuseableObserver; /* loaded from: classes2.dex */ public final class ObservableDistinctUntilChanged extends AbstractObservableWithUpstream { final Function b; final BiPredicate c; static final class DistinctUntilChangedObserver extends BasicFuseableObserver { final Function f; final BiPredicate g; K h; boolean i; DistinctUntilChangedObserver(Observer observer, Function function, BiPredicate biPredicate) { super(observer); this.f = function; this.g = biPredicate; } @Override // io.reactivex.Observer public void onNext(T t) { if (this.d) { return; } if (this.e != 0) { this.a.onNext(t); return; } try { K apply = this.f.apply(t); if (this.i) { boolean a = this.g.a(this.h, apply); this.h = apply; if (a) { return; } } else { this.i = true; this.h = apply; } this.a.onNext(t); } catch (Throwable th) { a(th); } } @Override // io.reactivex.internal.fuseable.SimpleQueue public T poll() throws Exception { while (true) { T poll = this.c.poll(); if (poll == null) { return null; } K apply = this.f.apply(poll); if (!this.i) { this.i = true; this.h = apply; return poll; } if (!this.g.a(this.h, apply)) { this.h = apply; return poll; } this.h = apply; } } @Override // io.reactivex.internal.fuseable.QueueFuseable public int requestFusion(int i) { return a(i); } } public ObservableDistinctUntilChanged(ObservableSource observableSource, Function function, BiPredicate biPredicate) { super(observableSource); this.b = function; this.c = biPredicate; } @Override // io.reactivex.Observable protected void subscribeActual(Observer observer) { this.a.subscribe(new DistinctUntilChangedObserver(observer, this.b, this.c)); } }