101 lines
3.1 KiB
Java
101 lines
3.1 KiB
Java
package io.reactivex.internal.operators.observable;
|
|
|
|
import io.reactivex.ObservableSource;
|
|
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.concurrent.Callable;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class ObservableScanSeed<T, R> extends AbstractObservableWithUpstream<T, R> {
|
|
final BiFunction<R, ? super T, R> b;
|
|
final Callable<R> c;
|
|
|
|
static final class ScanSeedObserver<T, R> implements Observer<T>, Disposable {
|
|
final Observer<? super R> a;
|
|
final BiFunction<R, ? super T, R> b;
|
|
R c;
|
|
Disposable d;
|
|
boolean e;
|
|
|
|
ScanSeedObserver(Observer<? super R> observer, BiFunction<R, ? super T, R> biFunction, R r) {
|
|
this.a = observer;
|
|
this.b = biFunction;
|
|
this.c = r;
|
|
}
|
|
|
|
@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 {
|
|
R apply = this.b.apply(this.c, t);
|
|
ObjectHelper.a(apply, "The accumulator returned a null value");
|
|
this.c = apply;
|
|
this.a.onNext(apply);
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
this.d.dispose();
|
|
onError(th);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onSubscribe(Disposable disposable) {
|
|
if (DisposableHelper.validate(this.d, disposable)) {
|
|
this.d = disposable;
|
|
this.a.onSubscribe(this);
|
|
this.a.onNext(this.c);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ObservableScanSeed(ObservableSource<T> observableSource, Callable<R> callable, BiFunction<R, ? super T, R> biFunction) {
|
|
super(observableSource);
|
|
this.b = biFunction;
|
|
this.c = callable;
|
|
}
|
|
|
|
@Override // io.reactivex.Observable
|
|
public void subscribeActual(Observer<? super R> observer) {
|
|
try {
|
|
R call = this.c.call();
|
|
ObjectHelper.a(call, "The seed supplied is null");
|
|
this.a.subscribe(new ScanSeedObserver(observer, this.b, call));
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
EmptyDisposable.error(th, observer);
|
|
}
|
|
}
|
|
}
|