
org.reactfx.FlatMapStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reactfx Show documentation
Show all versions of reactfx Show documentation
Reactive event streams for JavaFX
package org.reactfx;
import java.util.Optional;
import java.util.function.Function;
class FlatMapStream extends EventStreamBase {
private final EventStream source;
private final Function super T, ? extends EventStream> mapper;
private Subscription mappedSubscription = Subscription.EMPTY;
public FlatMapStream(
EventStream src,
Function super T, ? extends EventStream> f) {
this.source = src;
this.mapper = f;
}
@Override
protected Subscription observeInputs() {
Subscription s = source.subscribe(t -> {
mappedSubscription.unsubscribe();
mappedSubscription = mapper.apply(t).subscribe(this::emit);
});
return () -> {
s.unsubscribe();
mappedSubscription.unsubscribe();
mappedSubscription = Subscription.EMPTY;
};
}
}
class FlatMapOptStream extends EventStreamBase {
private final EventStream source;
private final Function super T, Optional> mapper;
public FlatMapOptStream(
EventStream src,
Function super T, Optional> f) {
this.source = src;
this.mapper = f;
}
@Override
protected Subscription observeInputs() {
return source.subscribe(t -> mapper.apply(t).ifPresent(this::emit));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy