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

cyclops.companion.vavr.Trys Maven / Gradle / Ivy

The newest version!
package cyclops.companion.vavr;


import cyclops.monads.VavrWitness.queue;
import io.vavr.Lazy;
import io.vavr.collection.*;
import io.vavr.concurrent.Future;
import io.vavr.control.*;
import com.aol.cyclops.vavr.hkt.*;
import cyclops.companion.CompletableFutures;
import cyclops.companion.Optionals;
import cyclops.control.Eval;
import cyclops.control.Maybe;
import cyclops.control.Reader;
import cyclops.control.Xor;
import cyclops.conversion.vavr.FromCyclopsReact;
import cyclops.monads.*;
import cyclops.monads.VavrWitness.*;
import com.aol.cyclops2.hkt.Higher;
import cyclops.function.Fn3;
import cyclops.function.Fn4;
import cyclops.function.Monoid;
import cyclops.monads.Witness.*;
import cyclops.stream.ReactiveSeq;
import cyclops.typeclasses.*;
import com.aol.cyclops.vavr.hkt.TryKind;
import cyclops.companion.Monoids;
import cyclops.conversion.vavr.ToCyclopsReact;
import cyclops.monads.VavrWitness;
import com.aol.cyclops2.data.collections.extensions.CollectionX;
import com.aol.cyclops2.types.Value;
import com.aol.cyclops2.types.anyM.AnyMValue;
import cyclops.collections.mutable.ListX;
import cyclops.function.Reducer;
import cyclops.monads.AnyM;
import cyclops.monads.VavrWitness.tryType;
import cyclops.monads.WitnessType;
import cyclops.monads.XorM;
import cyclops.typeclasses.comonad.Comonad;
import cyclops.typeclasses.foldable.Foldable;
import cyclops.typeclasses.foldable.Unfoldable;
import cyclops.typeclasses.functor.Functor;
import cyclops.typeclasses.instances.General;
import cyclops.typeclasses.monad.*;
import io.vavr.control.Try;
import lombok.experimental.UtilityClass;
import org.reactivestreams.Publisher;

import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Function;


import static com.aol.cyclops.vavr.hkt.TryKind.widen;

/**
 * Utility class for working with JDK Tryals
 *
 * @author johnmcclean
 *
 */
@UtilityClass
public class Trys {

    public static  ,T> XorM xorM(Try type){
        return XorM.right(anyM(type));
    }
    public static  ,T> XorM xorM(T type){
        return xorM(Try.success(type));
    }
    public static   Coproduct coproduct(Try type, InstanceDefinitions def1){
        return Coproduct.of(Xor.primary(widen(type)),def1, Instances.definitions());
    }
    public static   Coproduct coproductSuccess(T type, InstanceDefinitions def1){
        return coproduct(Try.success(type),def1);
    }
    public static   Coproduct coproductSuccess(Throwable e, InstanceDefinitions def1){
        return coproduct(Try.failure(e),def1);
    }
    public static  AnyMValue anyM(Try tryType) {
        return AnyM.ofValue(tryType, VavrWitness.tryType.INSTANCE);
    }
    /**
     * Perform a For Comprehension over a Try, accepting 3 generating function.
     * This results in a four level nested internal iteration over the provided Trys.
     *
     *  
     * {@code
     *
     *   import static com.aol.cyclops2.reactor.Trys.forEach4;
     *
    forEach4(Try.just(1),
    a-> Try.just(a+1),
    (a,b) -> Try.just(a+b),
    a                  (a,b,c) -> Try.just(a+b+c),
    Tuple::tuple)
     *
     * }
     * 
* * @param value1 top level Try * @param value2 Nested Try * @param value3 Nested Try * @param value4 Nested Try * @param yieldingFunction Generates a result per combination * @return Try with a combined value generated by the yielding function */ public static Try forEach4(Try value1, Function> value2, BiFunction> value3, Fn3> value4, Fn4 yieldingFunction) { return value1.flatMap(in -> { Try a = value2.apply(in); return a.flatMap(ina -> { Try b = value3.apply(in,ina); return b.flatMap(inb -> { Try c = value4.apply(in,ina,inb); return c.map(in2 -> yieldingFunction.apply(in, ina, inb, in2)); }); }); }); } /** * * Perform a For Comprehension over a Try, accepting 3 generating function. * This results in a four level nested internal iteration over the provided Trys. * *
     * {@code
     *
     *  import static com.aol.cyclops2.reactor.Trys.forEach4;
     *
     *  forEach4(Try.just(1),
    a-> Try.just(a+1),
    (a,b) -> Try.just(a+b),
    (a,b,c) -> Try.just(a+b+c),
    (a,b,c,d) -> a+b+c+d <100,
    Tuple::tuple);
     *
     * }
     * 
* * @param value1 top level Try * @param value2 Nested Try * @param value3 Nested Try * @param value4 Nested Try * @param filterFunction A filtering function, keeps values where the predicate holds * @param yieldingFunction Generates a result per combination * @return Try with a combined value generated by the yielding function */ public static Try forEach4(Try value1, Function> value2, BiFunction> value3, Fn3> value4, Fn4 filterFunction, Fn4 yieldingFunction) { return value1.flatMap(in -> { Try a = value2.apply(in); return a.flatMap(ina -> { Try b = value3.apply(in,ina); return b.flatMap(inb -> { Try c = value4.apply(in,ina,inb); return c.filter(in2->filterFunction.apply(in,ina,inb,in2)) .map(in2 -> yieldingFunction.apply(in, ina, inb, in2)); }); }); }); } /** * Perform a For Comprehension over a Try, accepting 2 generating function. * This results in a three level nested internal iteration over the provided Trys. * *
     * {@code
     *
     *   import static com.aol.cyclops2.reactor.Trys.forEach3;
     *
    forEach3(Try.just(1),
    a-> Try.just(a+1),
    (a,b) -> Try.just(a+b),
    Tuple::tuple)
     *
     * }
     * 
* * @param value1 top level Try * @param value2 Nested Try * @param value3 Nested Try * @param yieldingFunction Generates a result per combination * @return Try with a combined value generated by the yielding function */ public static Try forEach3(Try value1, Function> value2, BiFunction> value3, Fn3 yieldingFunction) { return value1.flatMap(in -> { Try a = value2.apply(in); return a.flatMap(ina -> { Try b = value3.apply(in,ina); return b.map(in2 -> yieldingFunction.apply(in, ina, in2)); }); }); } /** * * Perform a For Comprehension over a Try, accepting 2 generating function. * This results in a three level nested internal iteration over the provided Trys. * *
     * {@code
     *
     *  import static com.aol.cyclops2.reactor.Trys.forEach3;
     *
     *  forEach3(Try.just(1),
    a-> Try.just(a+1),
    (a,b) -> Try.just(a+b),
    (a,b,c) -> a+b+c <100,
    Tuple::tuple);
     *
     * }
     * 
* * @param value1 top level Try * @param value2 Nested Try * @param value3 Nested Try * @param filterFunction A filtering function, keeps values where the predicate holds * @param yieldingFunction Generates a result per combination * @return Try with a combined value generated by the yielding function */ public static Try forEach3(Try value1, Function> value2, BiFunction> value3, Fn3 filterFunction, Fn3 yieldingFunction) { return value1.flatMap(in -> { Try a = value2.apply(in); return a.flatMap(ina -> { Try b = value3.apply(in,ina); return b.filter(in2->filterFunction.apply(in,ina,in2)) .map(in2 -> yieldingFunction.apply(in, ina, in2)); }); }); } /** * Perform a For Comprehension over a Try, accepting a generating function. * This results in a two level nested internal iteration over the provided Trys. * *
     * {@code
     *
     *   import static com.aol.cyclops2.reactor.Trys.forEach;
     *
    forEach(Try.just(1),
    a-> Try.just(a+1),
    Tuple::tuple)
     *
     * }
     * 
* * @param value1 top level Try * @param value2 Nested Try * @param yieldingFunction Generates a result per combination * @return Try with a combined value generated by the yielding function */ public static Try forEach2(Try value1, Function> value2, BiFunction yieldingFunction) { return value1.flatMap(in -> { Try a = value2.apply(in); return a.map(in2 -> yieldingFunction.apply(in, in2)); }); } /** * * Perform a For Comprehension over a Try, accepting a generating function. * This results in a two level nested internal iteration over the provided Trys. * *
     * {@code
     *
     *  import static com.aol.cyclops2.reactor.Trys.forEach;
     *
     *  forEach(Try.just(1),
    a-> Try.just(a+1),
    (a,b) -> Try.just(a+b),
    (a,b,c) -> a+b+c <100,
    Tuple::tuple);
     *
     * }
     * 
* * @param value1 top level Try * @param value2 Nested Try * @param filterFunction A filtering function, keeps values where the predicate holds * @param yieldingFunction Generates a result per combination * @return Try with a combined value generated by the yielding function */ public static Try forEach2(Try value1, Function> value2, BiFunction filterFunction, BiFunction yieldingFunction) { return value1.flatMap(in -> { Try a = value2.apply(in); return a.filter(in2->filterFunction.apply(in,in2)) .map(in2 -> yieldingFunction.apply(in, in2)); }); } /** * Sequence operation, take a Collection of Trys and turn it into a Try with a Collection * By constrast with {@link Trys#sequencePresent(CollectionX)}, if any Trys are empty the result * is an empty Try * *
     * {@code
     *
     *  Try just = Try.of(10);
    Try none = Try.empty();
     *
     *  Try> opts = Trys.sequence(ListX.of(just, none, Try.of(1)));
    //Try.empty();
     *
     * }
     * 
* * * @param opts Maybes to Sequence * @return Maybe with a List of values */ public static Try> sequence(final CollectionX> opts) { return sequence(opts.stream()).map(s -> s.toListX()); } /** * Sequence operation, take a Collection of Trys and turn it into a Try with a Collection * Only successes are retained. By constrast with {@link Trys#sequence(CollectionX)} Try#empty types are * tolerated and ignored. * *
     * {@code
     *  Try just = Try.of(10);
    Try none = Try.empty();
     *
     * Try> maybes = Trys.sequencePresent(ListX.of(just, none, Try.of(1)));
    //Try.of(ListX.of(10, 1));
     * }
     * 
* * @param opts Trys to Sequence * @return Try with a List of values */ public static Try> sequencePresent(final CollectionX> opts) { return sequence(opts.stream().filter(Try::isSuccess)).map(s->s.toListX()); } /** * Sequence operation, take a Collection of Trys and turn it into a Try with a Collection * By constrast with {@link Trys#sequencePresent(CollectionX)} if any Try types are empty * the return type will be an empty Try * *
     * {@code
     *
     *  Try just = Try.of(10);
    Try none = Try.empty();
     *
     *  Try> maybes = Trys.sequence(ListX.of(just, none, Try.of(1)));
    //Try.empty();
     *
     * }
     * 
* * * @param opts Maybes to Sequence * @return Try with a List of values */ public static Try> sequence(final java.util.stream.Stream> opts) { return AnyM.sequence(opts.map(Trys::anyM), tryType.INSTANCE) .map(ReactiveSeq::fromStream) .to(VavrWitness::tryType); } /** * Accummulating operation using the supplied Reducer (@see cyclops2.Reducers). A typical use case is to accumulate into a Persistent Collection type. * Accumulates the present results, ignores empty Trys. * *
     * {@code
     *  Try just = Try.of(10);
    Try none = Try.empty();

     * Try> opts = Try.accumulateJust(ListX.of(just, none, Try.of(1)), Reducers.toPersistentSetX());
    //Try.of(PersistentSetX.of(10, 1)));
     *
     * }
     * 
* * @param tryTypeals Trys to accumulate * @param reducer Reducer to accumulate values with * @return Try with reduced value */ public static Try accumulatePresent(final CollectionX> tryTypeals, final Reducer reducer) { return sequencePresent(tryTypeals).map(s -> s.mapReduce(reducer)); } /** * Accumulate the results only from those Trys which have a value present, using the supplied mapping function to * convert the data from each Try before reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two * input values of the same type and returns the combined result) {@see cyclops2.Monoids }. * *
     * {@code
     *  Try just = Try.of(10);
    Try none = Try.empty();

     *  Try opts = Try.accumulateJust(ListX.of(just, none, Try.of(1)), i -> "" + i,
    Monoids.stringConcat);
    //Try.of("101")
     *
     * }
     * 
* * @param tryTypeals Trys to accumulate * @param mapper Mapping function to be applied to the result of each Try * @param reducer Monoid to combine values from each Try * @return Try with reduced value */ public static Try accumulatePresent(final CollectionX> tryTypeals, final Function mapper, final Monoid reducer) { return sequencePresent(tryTypeals).map(s -> s.map(mapper) .reduce(reducer)); } /** * Accumulate the results only from those Trys which have a value present, using the * supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two * input values of the same type and returns the combined result) {@see cyclops2.Monoids }. * *
     * {@code
     *  Try just = Try.of(10);
    Try none = Try.empty();

     *  Try opts = Try.accumulateJust(Monoids.stringConcat,ListX.of(just, none, Try.of(1)),
    );
    //Try.of("101")
     *
     * }
     * 
* * @param tryTypeals Trys to accumulate * @param reducer Monoid to combine values from each Try * @return Try with reduced value */ public static Try accumulatePresent(final Monoid reducer, final CollectionX> tryTypeals) { return sequencePresent(tryTypeals).map(s -> s .reduce(reducer)); } /** * Combine an Try with the provided value using the supplied BiFunction * *
     * {@code
     *  Trys.combine(Try.of(10),Maybe.just(20), this::add)
     *  //Try[30]
     *
     *  private int add(int a, int b) {
    return a + b;
    }
     *
     * }
     * 
* @param f Try to combine with a value * @param v Value to combine * @param fn Combining function * @return Try combined with supplied value */ public static Try combine(final Try f, final Value v, final BiFunction fn) { return narrow(FromCyclopsReact.toTry(ToCyclopsReact.toTry(f) .combine(v, fn))); } /** * Combine an Try with the provided Try using the supplied BiFunction * *
     * {@code
     *  Trys.combine(Try.of(10),Try.of(20), this::add)
     *  //Try[30]
     *
     *  private int add(int a, int b) {
    return a + b;
    }
     *
     * }
     * 
* * @param f Try to combine with a value * @param v Try to combine * @param fn Combining function * @return Try combined with supplied value, or empty Try if no value present */ public static Try combine(final Try f, final Try v, final BiFunction fn) { return combine(f,ToCyclopsReact.toTry(v),fn); } /** * Combine an Try with the provided Iterable (selecting one element if present) using the supplied BiFunction *
     * {@code
     *  Trys.zip(Try.of(10),Arrays.asList(20), this::add)
     *  //Try[30]
     *
     *  private int add(int a, int b) {
    return a + b;
    }
     *
     * }
     * 
* @param f Try to combine with first element in Iterable (if present) * @param v Iterable to combine * @param fn Combining function * @return Try combined with supplied Iterable, or empty Try if no value present */ public static Try zip(final Try f, final Iterable v, final BiFunction fn) { return narrow(FromCyclopsReact.toTry(ToCyclopsReact.toTry(f) .zip(v, fn))); } /** * Combine an Try with the provided Publisher (selecting one element if present) using the supplied BiFunction *
     * {@code
     *  Trys.zip(Flux.just(10),Try.of(10), this::add)
     *  //Try[30]
     *
     *  private int add(int a, int b) {
    return a + b;
    }
     *
     * }
     * 
* * @param p Publisher to combine * @param f Try to combine with * @param fn Combining function * @return Try combined with supplied Publisher, or empty Try if no value present */ public static Try zip(final Publisher p, final Try f, final BiFunction fn) { return narrow(FromCyclopsReact.toTry(ToCyclopsReact.toTry(f) .zipP(p, fn))); } /** * Narrow covariant type parameter * * @param tryTypeal Try with covariant type parameter * @return Narrowed Try */ public static Try narrow(final Try tryTypeal) { return (Try) tryTypeal; } public static Active allTypeclasses(Try tryType){ return Active.of(widen(tryType), Trys.Instances.definitions()); } public static Nested mapM(Try tryType, Function> fn, InstanceDefinitions defs){ Try> e = tryType.map(fn); TryKind> lk = widen(e); return Nested.of(lk, Trys.Instances.definitions(), defs); } /** * Companion class for creating Type Class instances for working with Trys * @author johnmcclean * */ @UtilityClass public static class Instances { public static InstanceDefinitions definitions() { return new InstanceDefinitions() { @Override public Functor functor() { return Instances.functor(); } @Override public Pure unit() { return Instances.unit(); } @Override public Applicative applicative() { return Instances.applicative(); } @Override public Monad monad() { return Instances.monad(); } @Override public Maybe> monadZero() { return Maybe.just(Instances.monadZero()); } @Override public Maybe> monadPlus() { return Maybe.just(Instances.monadPlus()); } @Override public Maybe> monadPlus(Monoid> m) { return Maybe.just(Instances.monadPlus(m)); } @Override public Maybe> traverse() { return Maybe.just(Instances.traverse()); } @Override public Maybe> foldable() { return Maybe.just(Instances.foldable()); } @Override public Maybe> comonad() { return Maybe.just(Instances.comonad()); } @Override public Maybe> unfoldable() { return Maybe.none(); } }; } /** * * Transform a Try, mulitplying every element by 2 * *
         * {@code
         *  TryKind tryType = Trys.functor().map(i->i*2, TryKind.widen(Try.successful(1));
         *
         *  //[2]
         *
         *
         * }
         * 
* * An example fluent api working with Trys *
         * {@code
         *   TryKind ft = Trys.unit()
        .unit("hello")
        .then(h->Trys.functor().map((String v) ->v.length(), h))
        .convert(TryKind::narrowK);
         *
         * }
         * 
* * * @return A functor for Trys */ public static Functor functor(){ BiFunction,Function,TryKind> map = Instances::map; return General.functor(map); } /** *
         * {@code
         * TryKind ft = Trys.unit()
        .unit("hello")
        .convert(TryKind::narrowK);

        //Arrays.asTry("hello"))
         *
         * }
         * 
* * * @return A factory for Trys */ public static Pure unit(){ return General.unit(Instances::of); } /** * *
         * {@code
         * import static com.aol.cyclops.hkt.jdk.TryKind.widen;
         * import static com.aol.cyclops.util.function.Lambda.l1;
         *
        Trys.applicative()
        .ap(widen(Try.successful(l1(this::multiplyByTwo))),widen(asTry(1,2,3)));
         *
         * //[2,4,6]
         * }
         * 
* * * Example fluent API *
         * {@code
         * TryKind> ftFn =Trys.unit()
         *                                                  .unit(Lambda.l1((Integer i) ->i*2))
         *                                                  .convert(TryKind::narrowK);

        TryKind ft = Trys.unit()
        .unit("hello")
        .then(h->Trys.functor().map((String v) ->v.length(), h))
        .then(h->Trys.applicative().ap(ftFn, h))
        .convert(TryKind::narrowK);

        //Arrays.asTry("hello".length()*2))
         *
         * }
         * 
* * * @return A zipper for Trys */ public static Applicative applicative(){ BiFunction>,TryKind,TryKind> ap = Instances::ap; return General.applicative(functor(), unit(), ap); } /** * *
         * {@code
         * import static com.aol.cyclops.hkt.jdk.TryKind.widen;
         * TryKind ft  = Trys.monad()
        .flatMap(i->widen(Try.successful(i), widen(Try.successful(3))
        .convert(TryKind::narrowK);
         * }
         * 
* * Example fluent API *
         * {@code
         *    TryKind ft = Trys.unit()
        .unit("hello")
        .then(h->Trys.monad().flatMap((String v) ->Trys.unit().unit(v.length()), h))
        .convert(TryKind::narrowK);

        //Arrays.asTry("hello".length())
         *
         * }
         * 
* * @return Type class with monad functions for Trys */ public static Monad monad(){ BiFunction,Function>,Higher> flatMap = Instances::flatMap; return General.monad(applicative(), flatMap); } /** * *
         * {@code
         *  TryKind ft = Trys.unit()
        .unit("hello")
        .then(h->Trys.monadZero().filter((String t)->t.startsWith("he"), h))
        .convert(TryKind::narrowK);

        //Arrays.asTry("hello"));
         *
         * }
         * 
* * * @return A filterable monad (with default value) */ public static MonadZero monadZero(){ return General.monadZero(monad(), TryKind.failed(new NoSuchElementException())); } /** *
         * {@code
         *  TryKind ft = Trys.monadPlus()
        .plus(TryKind.widen(Arrays.asTry()), TryKind.widen(Try.successful((10)))
        .convert(TryKind::narrowK);
        //Try(10)
         *
         * }
         * 
* @return Type class for combining Trys by concatenation */ public static MonadPlus monadPlus(){ Monoid> mn = Monoids.firstTrySuccess(new NoSuchElementException()); Monoid> m = Monoid.of(widen(mn.zero()), (f, g)-> widen( mn.apply(ToCyclopsReact.toTry(f), ToCyclopsReact.toTry(g)))); Monoid> m2= (Monoid)m; return General.monadPlus(monadZero(),m2); } /** * *
         * {@code
         *  Monoid> m = Monoid.of(TryKind.widen(Try.failed(e), (a,b)->a.isEmpty() ? b : a);
        TryKind ft = Trys.monadPlus(m)
        .plus(TryKind.widen(Try.successful(5), TryKind.widen(Try.successful(10))
        .convert(TryKind::narrowK);
        //Try(5)
         *
         * }
         * 
* * @param m Monoid to use for combining Trys * @return Type class for combining Trys */ public static MonadPlus monadPlus(Monoid> m){ Monoid> m2= (Monoid)m; return General.monadPlus(monadZero(),m2); } /** * @return Type class for traversables with traverse / sequence operations */ public static Traverse traverse(){ return General.traverseByTraverse(applicative(), Instances::traverseA); } /** * *
         * {@code
         * int sum  = Trys.foldable()
        .foldLeft(0, (a,b)->a+b, TryKind.widen(Try.successful(4));

        //4
         *
         * }
         * 
* * * @return Type class for folding / reduction operations */ public static Foldable foldable(){ BiFunction,Higher,T> foldRightFn = (m, l)-> m.apply(m.zero(), TryKind.narrow(l).get()); BiFunction,Higher,T> foldLeftFn = (m, l)-> m.apply(m.zero(), TryKind.narrow(l).get()); return General.foldable(foldRightFn, foldLeftFn); } public static Comonad comonad(){ Function, ? extends T> extractFn = maybe -> maybe.convert(TryKind::narrow).get(); return General.comonad(functor(), unit(), extractFn); } private TryKind of(T value){ return widen(Try.success(value)); } private static TryKind ap(TryKind> lt, TryKind list){ return widen(ToCyclopsReact.toTry(lt).combine(ToCyclopsReact.toTry(list), (a, b)->a.apply(b))); } private static Higher flatMap(Higher lt, Function> fn){ return widen(TryKind.narrow(lt).flatMap(fn.andThen(TryKind::narrowK))); } private static TryKind map(TryKind lt, Function fn){ return widen(lt.map(fn)); } private static Higher> traverseA(Applicative applicative, Function> fn, Higher ds){ Try tryType = TryKind.narrow(ds); return applicative.map(TryKind::successful, fn.apply(tryType.get())); } } public static interface TryNested{ public static Nested lazy(Try> type){ return Nested.of(widen(type.map(LazyKind::widen)),Instances.definitions(),Lazys.Instances.definitions()); } public static Nested tryTry(Try> type){ return Nested.of(widen(type.map(TryKind::widen)),Instances.definitions(),Trys.Instances.definitions()); } public static Nested future(Try> type){ return Nested.of(widen(type.map(FutureKind::widen)),Instances.definitions(),Futures.Instances.definitions()); } public static Nested queue(Try> nested){ return Nested.of(widen(nested.map(QueueKind::widen)),Instances.definitions(),Queues.Instances.definitions()); } public static Nested, R> either(Try> nested){ return Nested.of(widen(nested.map(EitherKind::widen)),Instances.definitions(),Eithers.Instances.definitions()); } public static Nested stream(Try> nested){ return Nested.of(widen(nested.map(StreamKind::widen)),Instances.definitions(),Streams.Instances.definitions()); } public static Nested list(Try> nested){ return Nested.of(widen(nested.map(ListKind::widen)), Instances.definitions(),Lists.Instances.definitions()); } public static Nested array(Try> nested){ return Nested.of(widen(nested.map(ArrayKind::widen)),Instances.definitions(),Arrays.Instances.definitions()); } public static Nested vector(Try> nested){ return Nested.of(widen(nested.map(VectorKind::widen)),Instances.definitions(),Vectors.Instances.definitions()); } public static Nested set(Try> nested){ return Nested.of(widen(nested.map(HashSetKind::widen)),Instances.definitions(), HashSets.Instances.definitions()); } public static Nested reactiveSeq(Try> nested){ TryKind> x = widen(nested); TryKind> y = (TryKind)x; return Nested.of(y,Instances.definitions(),ReactiveSeq.Instances.definitions()); } public static Nested maybe(Try> nested){ TryKind> x = widen(nested); TryKind> y = (TryKind)x; return Nested.of(y,Instances.definitions(),Maybe.Instances.definitions()); } public static Nested eval(Try> nested){ TryKind> x = widen(nested); TryKind> y = (TryKind)x; return Nested.of(y,Instances.definitions(),Eval.Instances.definitions()); } public static Nested cyclopsFuture(Try> nested){ TryKind> x = widen(nested); TryKind> y = (TryKind)x; return Nested.of(y,Instances.definitions(),cyclops.async.Future.Instances.definitions()); } public static Nested, P> xor(Try> nested){ TryKind> x = widen(nested); TryKind, P>> y = (TryKind)x; return Nested.of(y,Instances.definitions(),Xor.Instances.definitions()); } public static Nested, T> reader(Try> nested){ TryKind> x = widen(nested); TryKind, T>> y = (TryKind)x; return Nested.of(y,Instances.definitions(),Reader.Instances.definitions()); } public static Nested, P> cyclopsTry(Try> nested){ TryKind> x = widen(nested); TryKind, P>> y = (TryKind)x; return Nested.of(y,Instances.definitions(),cyclops.control.Try.Instances.definitions()); } public static Nested tryTypeal(Try> nested){ TryKind> x = widen(nested); TryKind> y = (TryKind)x; return Nested.of(y,Instances.definitions(), Optionals.Instances.definitions()); } public static Nested completableTry(Try> nested){ TryKind> x = widen(nested); TryKind> y = (TryKind)x; return Nested.of(y,Instances.definitions(), CompletableFutures.Instances.definitions()); } public static Nested javaStream(Try> nested){ TryKind> x = widen(nested); TryKind> y = (TryKind)x; return Nested.of(y,Instances.definitions(), cyclops.companion.Streams.Instances.definitions()); } } public static interface NestedTry{ public static Nested reactiveSeq(ReactiveSeq> nested){ ReactiveSeq> x = nested.map(TryKind::widenK); return Nested.of(x,ReactiveSeq.Instances.definitions(),Instances.definitions()); } public static Nested maybe(Maybe> nested){ Maybe> x = nested.map(TryKind::widenK); return Nested.of(x,Maybe.Instances.definitions(),Instances.definitions()); } public static Nested eval(Eval> nested){ Eval> x = nested.map(TryKind::widenK); return Nested.of(x,Eval.Instances.definitions(),Instances.definitions()); } public static Nested cyclopsFuture(cyclops.async.Future> nested){ cyclops.async.Future> x = nested.map(TryKind::widenK); return Nested.of(x,cyclops.async.Future.Instances.definitions(),Instances.definitions()); } public static Nested,tryType, P> xor(Xor> nested){ Xor> x = nested.map(TryKind::widenK); return Nested.of(x,Xor.Instances.definitions(),Instances.definitions()); } public static Nested,tryType, T> reader(Reader> nested){ Reader> x = nested.map(TryKind::widenK); return Nested.of(x,Reader.Instances.definitions(),Instances.definitions()); } public static Nested,tryType, P> cyclopsTry(cyclops.control.Try, S> nested){ cyclops.control.Try, S> x = nested.map(TryKind::widenK); return Nested.of(x,cyclops.control.Try.Instances.definitions(),Instances.definitions()); } public static Nested tryTypeal(Optional> nested){ Optional> x = nested.map(TryKind::widenK); return Nested.of(Optionals.OptionalKind.widen(x), Optionals.Instances.definitions(), Instances.definitions()); } public static Nested completableTry(CompletableFuture> nested){ CompletableFuture> x = nested.thenApply(TryKind::widenK); return Nested.of(CompletableFutures.CompletableFutureKind.widen(x), CompletableFutures.Instances.definitions(),Instances.definitions()); } public static Nested javaStream(java.util.stream.Stream> nested){ java.util.stream.Stream> x = nested.map(TryKind::widenK); return Nested.of(cyclops.companion.Streams.StreamKind.widen(x), cyclops.companion.Streams.Instances.definitions(),Instances.definitions()); } } }