org.reactfx.EitherEventStream 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.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import javafx.application.Platform;
import org.reactfx.util.Either;
/**
* @deprecated Since 1.2.1. The utility of {@code EitherEventStream} over
* just {@code EventStream>} is questionable and probably not worth
* maintaining a special implementation. Let us know if you use it and your code
* would get much less readable without it.
*/
@Deprecated
public interface EitherEventStream extends EventStream> {
default Subscription subscribe(
Consumer super L> leftSubscriber,
Consumer super R> rightSubscriber,
Consumer super Throwable> onError) {
return subscribe(either -> {
either.ifLeft(leftSubscriber);
either.ifRight(rightSubscriber);
}, onError);
}
@Deprecated
default Subscription watch(
Consumer super L> leftSubscriber,
Consumer super R> rightSubscriber,
Consumer super Throwable> monitor) {
return subscribe(leftSubscriber, rightSubscriber, monitor);
}
default EventStream left() {
return filterMap(Either::isLeft, Either::getLeft);
}
default EventStream right() {
return filterMap(Either::isRight, Either::getRight);
}
@Override
default EitherEventStream hook(
Consumer super Either> sideEffect) {
return new SideEffectEitherStream<>(this, sideEffect);
}
default EitherEventStream hook(
Consumer super L> leftSideEffect,
Consumer super R> rightSideEffect) {
return hook(either -> either.exec(leftSideEffect, rightSideEffect));
}
@Override
default EitherEventStream filter(
Predicate super Either> predicate) {
return new FilterEitherStream<>(this, predicate);
}
@Override
default EitherEventStream distinct() {
return new DistinctEitherStream<>(this);
}
default EitherEventStream map(
Function super L, ? extends L1> leftMap,
Function super R, ? extends R1> rightMap) {
return split(either -> either.map(leftMap, rightMap));
}
default EitherEventStream mapLeft(
Function super L, ? extends L1> f) {
return split(either -> either.mapLeft(f));
}
default EitherEventStream mapRight(
Function super R, ? extends R1> f) {
return split(either -> either.mapRight(f));
}
default EitherEventStream split(
Function super L, Either> leftMap,
Function super R, Either> rightMap) {
return split(either -> either.flatMap(leftMap, rightMap));
}
default EitherEventStream splitLeft(
Function super L, Either> leftMap) {
return split(either -> either.flatMapLeft(leftMap));
}
default EitherEventStream splitRight(
Function super R, Either> rightMap) {
return split(either -> either.flatMapRight(rightMap));
}
default EventStream unify(
Function super L, ? extends T> leftMap,
Function super R, ? extends T> rightMap) {
return map(either -> either.unify(leftMap, rightMap));
}
@Override
default EitherEventStream emitOn(EventStream> impulse) {
return new EmitOnEitherStream<>(this, impulse);
}
@Override
default EitherEventStream emitOnEach(EventStream> impulse) {
return new EmitOnEachEitherStream<>(this, impulse);
}
@Override
default EitherEventStream repeatOn(EventStream> impulse) {
return new RepeatOnEitherStream<>(this, impulse);
}
@Override
default InterceptableEitherEventStream interceptable() {
if(this instanceof InterceptableEitherEventStream) {
return (InterceptableEitherEventStream) this;
} else {
return new InterceptableEitherEventStreamImpl(this);
}
}
@Override
default EitherEventStream threadBridge(
Executor sourceThreadExecutor,
Executor targetThreadExecutor) {
return new EitherThreadBridge(this, sourceThreadExecutor, targetThreadExecutor);
}
@Override
default EitherEventStream threadBridgeFromFx(Executor targetThreadExecutor) {
return threadBridge(Platform::runLater, targetThreadExecutor);
}
@Override
default EitherEventStream threadBridgeToFx(Executor sourceThreadExecutor) {
return threadBridge(sourceThreadExecutor, Platform::runLater);
}
@Override
default EitherEventStream guardedBy(Guardian... guardians) {
return new GuardedEitherStream<>(this, guardians);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy