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

cyclops.conversion.vavr.ToCyclopsReact Maven / Gradle / Ivy

The newest version!
package cyclops.conversion.vavr;

import com.aol.cyclops2.types.Zippable;
import cyclops.async.Future;
import cyclops.control.Eval;
import cyclops.control.Maybe;
import cyclops.control.Try;
import cyclops.control.Xor;
import io.vavr.Lazy;
import io.vavr.control.Either;
import io.vavr.control.Option;


public class ToCyclopsReact {

    public static  Future[] futures(io.vavr.concurrent.Future... futures){

        Future[] array = new Future[futures.length];
        for(int i=0;i Future future(io.vavr.concurrent.Future future){
        Future res = Future.future();
        future.onSuccess(v->res.complete(v))
                .onFailure(t->res.completeExceptionally(t));
        return res;
    }

    public static  Xor xor(Either either){
        return either.fold(Xor::secondary,Xor::primary);
    }
    public static  Try toTry(io.vavr.control.Try t){

        if(t.isFailure()){
            return Try.failure(t.getCause());
        }
        return Try.success(t.get());
    }

    public static  Maybe maybe(Option opt){
        return opt.isDefined() ? Maybe.just(opt.get()) : Maybe.none();
    }
    public static  Eval eval(Lazy opt){
        return Eval.later(opt);
    }
    public static  cyclops.control.lazy.Either either(io.vavr.concurrent.Future either){
        return cyclops.control.lazy.Either.fromFuture(future(either));

    }

    public static  Maybe maybe(io.vavr.concurrent.Future opt){
        return Maybe.fromFuture(future(opt));
    }
    public static  Eval eval(io.vavr.concurrent.Future opt){
        return Eval.fromFuture(future(opt));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy