public static EitherUnsafe <L, TryOption <B> > Traverse <L, A, B>(this TryOption <EitherUnsafe <L, A> > ma, Func <A, B> f) { var tres = ma.Try(); if (tres.IsBottom) { return(EitherUnsafe <L, TryOption <B> > .Bottom); } else if (tres.IsFaulted) { return(Right(TryOptionFail <B>(tres.Exception))); } else if (tres.IsNone) { return(Right(TryOptional <B>(None))); } else if (tres.Value.Value.IsLeft) { return(EitherUnsafe <L, TryOption <B> > .Left((L)tres.Value.Value)); } else { return(EitherUnsafe <L, TryOption <B> > .Right(TryOption(f((A)tres.Value.Value)))); } }
public static TryOption <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, TryOption <A> > ma, Func <A, B> f) => () => { if (ma.IsBottom) { return(OptionalResult <EitherUnsafe <L, B> > .Bottom); } else if (ma.IsLeft) { return(new OptionalResult <EitherUnsafe <L, B> >(LeftUnsafe <L, B>(ma.LeftValue))); } else { var mr = ma.RightValue(); if (mr.IsBottom) { return(new OptionalResult <EitherUnsafe <L, B> >(BottomException.Default)); } if (mr.IsFaulted) { return(new OptionalResult <EitherUnsafe <L, B> >(mr.Exception)); } if (mr.IsNone) { return(OptionalResult <EitherUnsafe <L, B> > .None); } return(new OptionalResult <EitherUnsafe <L, B> >(EitherUnsafe <L, B> .Right(f(mr.Value.Value)))); } };
public static EitherUnsafe <L, Identity <B> > Traverse <L, A, B>(this Identity <EitherUnsafe <L, A> > ma, Func <A, B> f) { if (ma.Value.IsLeft) { return(EitherUnsafe <L, Identity <B> > .Left((L)ma.Value)); } else { return(EitherUnsafe <L, Identity <B> > .Right(new Identity <B>(f((A)ma.Value)))); } }
public static async ValueTask <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, ValueTask <A> > ma, Func <A, B> f) { if (ma.IsBottom) { return(EitherUnsafe <L, B> .Bottom); } else if (ma.IsLeft) { return(EitherUnsafe <L, B> .Left(ma.LeftValue)); } return(EitherUnsafe <L, B> .Right(f(await ma.RightValue.ConfigureAwait(false)))); }
public static EitherUnsafe <L, EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, EitherUnsafe <L, A> > ma, Func <A, B> f) { if (ma.IsLeft) { return(Right(EitherUnsafe <L, B> .Left((L)ma))); } else { var mb = (EitherUnsafe <L, A>)ma; if (mb.IsLeft) { return(EitherUnsafe <L, EitherUnsafe <L, B> > .Left((L)mb)); } else { return(EitherUnsafe <L, EitherUnsafe <L, B> > .Right(f((A)mb))); } } }
public static EitherUnsafe <L, Validation <Fail, B> > Traverse <Fail, L, A, B>(this Validation <Fail, EitherUnsafe <L, A> > ma, Func <A, B> f) { if (ma.IsFail) { return(Right(Validation <Fail, B> .Fail(ma.FailValue))); } else { var mb = ma.SuccessValue; if (mb.IsLeft) { return(EitherUnsafe <L, Validation <Fail, B> > .Left((L)mb)); } else { return(EitherUnsafe <L, Validation <Fail, B> > .Right(f((A)mb))); } } }
public static EitherUnsafe <L, Fin <B> > Traverse <L, A, B>(this Fin <EitherUnsafe <L, A> > ma, Func <A, B> f) { if (ma.IsFail) { return(Right(ma.Cast <B>())); } else { var mb = (EitherUnsafe <L, A>)ma; if (mb.IsLeft) { return(EitherUnsafe <L, Fin <B> > .Left((L)mb)); } else { return(EitherUnsafe <L, Fin <B> > .Right(f((A)mb))); } } }
public static EitherUnsafe <Fail, Validation <MonoidFail, Fail, B> > Traverse <MonoidFail, Fail, A, B>(this Validation <MonoidFail, Fail, EitherUnsafe <Fail, A> > ma, Func <A, B> f) where MonoidFail : struct, Monoid <Fail>, Eq <Fail> { if (ma.IsFail) { return(Right(Validation <MonoidFail, Fail, B> .Fail(ma.FailValue))); } else { var mb = ma.SuccessValue; if (mb.IsLeft) { return(EitherUnsafe <Fail, Validation <MonoidFail, Fail, B> > .Left((Fail)mb)); } else { return(EitherUnsafe <Fail, Validation <MonoidFail, Fail, B> > .Right(f((A)mb))); } } }
public static EitherUnsafe <L, Eff <B> > Traverse <L, A, B>(this Eff <EitherUnsafe <L, A> > ma, Func <A, B> f) { var tres = ma.Run(); if (tres.IsBottom) { return(EitherUnsafe <L, Eff <B> > .Bottom); } else if (tres.IsFail) { return(RightUnsafe(FailEff <B>(tres.Error))); } else if (tres.Value.IsLeft) { return(EitherUnsafe <L, Eff <B> > .Left((L)tres.Value)); } else { return(EitherUnsafe <L, Eff <B> > .Right(SuccessEff(f((A)tres.Value)))); } }
/// <summary> /// Either constructor /// Constructs an Either in a Right state /// </summary> /// <typeparam name="L">Left</typeparam> /// <typeparam name="R">Right</typeparam> /// <param name="value">Right value</param> /// <returns>A new Either instance</returns> public static EitherUnsafe <L, R> RightUnsafe <L, R>(R value) => EitherUnsafe <L, R> .Right(value);
public static EitherUnsafe <R, L> RightUnsafe <R, L>(R value) => EitherUnsafe <R, L> .Right(value);