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

com.aol.cyclops.reactor.Reactor Maven / Gradle / Ivy

There is a newer version: 9.0.0-MI7
Show newest version
package com.aol.cyclops.reactor;

import java.util.function.BiFunction;
import java.util.function.Function;

import org.reactivestreams.Publisher;

import com.aol.cyclops.control.AnyM;
import com.aol.cyclops.control.For;
import com.aol.cyclops.control.FutureW;
import com.aol.cyclops.control.ReactiveSeq;
import com.aol.cyclops.control.monads.transformers.FutureWT;
import com.aol.cyclops.control.monads.transformers.seq.FutureWTSeq;
import com.aol.cyclops.reactor.transformer.FluxT;
import com.aol.cyclops.reactor.transformer.FluxTSeq;
import com.aol.cyclops.types.anyM.AnyMSeq;
import com.aol.cyclops.types.anyM.AnyMValue;
import com.aol.cyclops.util.function.QuadFunction;
import com.aol.cyclops.util.function.TriFunction;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public interface Reactor {

    public static  AnyMSeq fromFluxT(FluxT flux) {
        return AnyM.ofSeq(flux);
    }

    public static  AnyMSeq flux(Flux flux) {
        return AnyM.ofSeq(flux);
    }

    public static  FluxTSeq fluxT(Publisher> nested) {
        return FluxT.fromPublisher(nested);
    }

    public static  AnyMValue mono(Mono mono) {
        return AnyM.ofValue(mono);
    }

    public static  FutureWTSeq monoT(Publisher> nested) {
        return FutureWT.fromPublisher(Flux.from(nested)
                                          .map(f -> FutureW.of(f.toFuture())));
    }

    public interface ForFlux {

        static  Flux each4(Flux value1,
                Function> value2,
                BiFunction> value3,
                TriFunction> value4,
                QuadFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(flux(value1))
                                 .anyM(a -> flux(value2.apply(a)))
                                 .anyM(a -> b -> flux(value3.apply(a, b)))
                                 .anyM(a -> b -> c -> flux(value4.apply(a, b, c)))
                                 .yield4(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  Flux each4(Flux value1,
                Function> value2,
                BiFunction> value3,
                TriFunction> value4,
                QuadFunction filterFunction,
                QuadFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(flux(value1))
                                 .anyM(a -> flux(value2.apply(a)))
                                 .anyM(a -> b -> flux(value3.apply(a, b)))
                                 .anyM(a -> b -> c -> flux(value4.apply(a, b, c)))
                                 .filter(a -> b -> c -> d -> filterFunction.apply(a, b, c, d))
                                 .yield4(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  Flux each3(Flux value1,
                Function> value2,
                BiFunction> value3,
                TriFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(flux(value1))
                                 .anyM(a -> flux(value2.apply(a)))
                                 .anyM(a -> b -> flux(value3.apply(a, b)))
                                 .yield3(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  Flux each3(Flux value1,
                Function> value2,
                BiFunction> value3,
                TriFunction filterFunction,
                TriFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(flux(value1))
                                 .anyM(a -> flux(value2.apply(a)))
                                 .anyM(a -> b -> flux(value3.apply(a, b)))
                                 .filter(a -> b -> c -> filterFunction.apply(a, b, c))
                                 .yield3(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  Flux each2(Flux value1, Function> value2,
                BiFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(flux(value1))
                                 .anyM(a -> flux(value2.apply(a)))
                                 .yield2(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  Flux each2(Flux value1, Function> value2,
                BiFunction filterFunction,
                BiFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(flux(value1))
                                 .anyM(a -> flux(value2.apply(a)))
                                 .filter(a -> b -> filterFunction.apply(a, b))
                                 .yield2(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }
    }

    public interface ForFluxTransformer {

        static  FluxT each4(FluxT value1,
                Function> value2,
                BiFunction> value3,
                TriFunction> value4,
                QuadFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(fromFluxT(value1))
                                 .anyM(a -> fromFluxT(value2.apply(a)))
                                 .anyM(a -> b -> fromFluxT(value3.apply(a, b)))
                                 .anyM(a -> b -> c -> fromFluxT(value4.apply(a, b, c)))
                                 .yield4(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  FluxT each4(FluxT value1,
                Function> value2,
                BiFunction> value3,
                TriFunction> value4,
                QuadFunction filterFunction,
                QuadFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(fromFluxT(value1))
                                 .anyM(a -> fromFluxT(value2.apply(a)))
                                 .anyM(a -> b -> fromFluxT(value3.apply(a, b)))
                                 .anyM(a -> b -> c -> fromFluxT(value4.apply(a, b, c)))
                                 .filter(a -> b -> c -> d -> filterFunction.apply(a, b, c, d))
                                 .yield4(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  FluxT each3(FluxT value1,
                Function> value2,
                BiFunction> value3,
                TriFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(fromFluxT(value1))
                                 .anyM(a -> fromFluxT(value2.apply(a)))
                                 .anyM(a -> b -> fromFluxT(value3.apply(a, b)))
                                 .yield3(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  FluxT each3(FluxT value1,
                Function> value2,
                BiFunction> value3,
                TriFunction filterFunction,
                TriFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(fromFluxT(value1))
                                 .anyM(a -> fromFluxT(value2.apply(a)))
                                 .anyM(a -> b -> fromFluxT(value3.apply(a, b)))
                                 .filter(a -> b -> c -> filterFunction.apply(a, b, c))
                                 .yield3(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  FluxT each2(FluxT value1, Function> value2,
                BiFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(fromFluxT(value1))
                                 .anyM(a -> fromFluxT(value2.apply(a)))
                                 .yield2(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }

        static  FluxT each2(FluxT value1, Function> value2,
                BiFunction filterFunction,
                BiFunction yieldingFunction) {

            return AnyM.ofSeq(For.anyM(fromFluxT(value1))
                                 .anyM(a -> fromFluxT(value2.apply(a)))
                                 .filter(a -> b -> filterFunction.apply(a, b))
                                 .yield2(yieldingFunction)
                                 .unwrap())
                       .unwrap();

        }
    }

    public interface ForMono {

        static  Mono each4(Mono value1,
                Function> value2,
                BiFunction> value3,
                TriFunction> value4,
                QuadFunction yieldingFunction) {

            return AnyM.ofValue(For.anyM(mono(value1))
                                   .anyM(a -> mono(value2.apply(a)))
                                   .anyM(a -> b -> mono(value3.apply(a, b)))
                                   .anyM(a -> b -> c -> mono(value4.apply(a, b, c)))
                                   .yield4(yieldingFunction)
                                   .unwrap())
                       .unwrap();

        }

        static  Mono each4(Mono value1,
                Function> value2,
                BiFunction> value3,
                TriFunction> value4,
                QuadFunction filterFunction,
                QuadFunction yieldingFunction) {

            return AnyM.ofValue(For.anyM(mono(value1))
                                   .anyM(a -> mono(value2.apply(a)))
                                   .anyM(a -> b -> mono(value3.apply(a, b)))
                                   .anyM(a -> b -> c -> mono(value4.apply(a, b, c)))
                                   .filter(a -> b -> c -> d -> filterFunction.apply(a, b, c, d))
                                   .yield4(yieldingFunction)
                                   .unwrap())
                       .unwrap();

        }

        static  Mono each3(Mono value1,
                Function> value2,
                BiFunction> value3,
                TriFunction yieldingFunction) {

            return AnyM.ofValue(For.anyM(mono(value1))
                                   .anyM(a -> mono(value2.apply(a)))
                                   .anyM(a -> b -> mono(value3.apply(a, b)))
                                   .yield3(yieldingFunction)
                                   .unwrap())
                       .unwrap();

        }

        static  Mono each3(Mono value1,
                Function> value2,
                BiFunction> value3,
                TriFunction filterFunction,
                TriFunction yieldingFunction) {

            return AnyM.ofValue(For.anyM(mono(value1))
                                   .anyM(a -> mono(value2.apply(a)))
                                   .anyM(a -> b -> mono(value3.apply(a, b)))
                                   .filter(a -> b -> c -> filterFunction.apply(a, b, c))
                                   .yield3(yieldingFunction)
                                   .unwrap())
                       .unwrap();

        }

        static  Mono each2(Mono value1, Function> value2,
                BiFunction yieldingFunction) {

            return AnyM.ofValue(For.anyM(mono(value1))
                                   .anyM(a -> mono(value2.apply(a)))
                                   .yield2(yieldingFunction)
                                   .unwrap())
                       .unwrap();

        }

        static  Mono each2(Mono value1, Function> value2,
                BiFunction filterFunction,
                BiFunction yieldingFunction) {

            return AnyM.ofValue(For.anyM(mono(value1))
                                   .anyM(a -> mono(value2.apply(a)))
                                   .filter(a -> b -> filterFunction.apply(a, b))
                                   .yield2(yieldingFunction)
                                   .unwrap())
                       .unwrap();

        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy