I'm trying to implement a lambda expression in a switchMap
callback but it complains about the parameter type and I've been unable to figure out why.
public class Notifier {
public ReplaySubject emitter = ReplaySubject.create();
private PublishSubject status = PublishSubject.create();
private Observable<Long> interval$;
private Disposable notificationSubscription;
public Notifier() {
interval$ = Observable
.interval(5000, TimeUnit.MILLISECONDS)
.concatMap((i) -> {
Observable nextNotification$ = interval$
.share()
.take(1);
//noinspection unchecked
return status
.startWith(new Boolean(true))
.switchMap((Boolean value) -> {
if (!value.booleanValue()) {
return Observable.empty();
}
return Observable.timer(1000, TimeUnit.MILLISECONDS).zip(nextNotification$, (val) -> i);
});
});
notificationSubscription = interval$.subscribe(this::newNotification);
}
}
It's the .switchMap((Boolean value) -> { ... }
line that complains.
I tried using a Consumer
too but then I got other issues which was even worse.
How can I tweak this to work as expected?