All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reactfx.EitherEventStream Maven / Gradle / Ivy

There is a newer version: 2.0-M5
Show newest version
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 leftSubscriber,
            Consumer rightSubscriber,
            Consumer onError) {
        return subscribe(either -> {
            either.ifLeft(leftSubscriber);
            either.ifRight(rightSubscriber);
        }, onError);
    }

    @Deprecated
    default Subscription watch(
            Consumer leftSubscriber,
            Consumer rightSubscriber,
            Consumer 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> sideEffect) {
        return new SideEffectEitherStream<>(this, sideEffect);
    }

    default EitherEventStream hook(
            Consumer leftSideEffect,
            Consumer rightSideEffect) {
        return hook(either -> either.exec(leftSideEffect, rightSideEffect));
    }

    @Override
    default EitherEventStream filter(
            Predicate> predicate) {
        return new FilterEitherStream<>(this, predicate);
    }

    @Override
    default EitherEventStream distinct() {
        return new DistinctEitherStream<>(this);
    }

    default  EitherEventStream map(
            Function leftMap,
            Function rightMap) {
        return split(either -> either.map(leftMap, rightMap));
    }

    default  EitherEventStream mapLeft(
            Function f) {
        return split(either -> either.mapLeft(f));
    }

    default  EitherEventStream mapRight(
            Function f) {
        return split(either -> either.mapRight(f));
    }

    default  EitherEventStream split(
            Function> leftMap,
            Function> rightMap) {
        return split(either -> either.flatMap(leftMap, rightMap));
    }

    default  EitherEventStream splitLeft(
            Function> leftMap) {
        return split(either -> either.flatMapLeft(leftMap));
    }

    default  EitherEventStream splitRight(
            Function> rightMap) {
        return split(either -> either.flatMapRight(rightMap));
    }

    default  EventStream unify(
            Function leftMap,
            Function 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