Ejemplo n.º 1
0
        public static TryOptionAsync <TryOption <B> > Traverse <A, B>(this TryOption <TryOptionAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <TryOption <B> > > Go(TryOption <TryOptionAsync <A> > ma, Func <A, B> f)
            {
                var ra = ma.Try();

                if (ra.IsBottom)
                {
                    return(OptionalResult <TryOption <B> > .Bottom);
                }
                if (ra.IsNone)
                {
                    return(new OptionalResult <TryOption <B> >(TryOptional <B>(None)));
                }
                if (ra.IsFaulted)
                {
                    return(new OptionalResult <TryOption <B> >(TryOptionFail <B>(ra.Exception)));
                }
                var rb = await ra.Value.Value.Try().ConfigureAwait(false);

                if (rb.IsFaulted)
                {
                    return(new OptionalResult <TryOption <B> >(rb.Exception));
                }
                if (rb.IsNone)
                {
                    return(OptionalResult <TryOption <B> > .None);
                }
                return(OptionalResult <TryOption <B> > .Some(TryOption <B>(f(rb.Value.Value))));
            }
        }
Ejemplo n.º 2
0
        public static TryOptionAsync <Eff <B> > Traverse <A, B>(this Eff <TryOptionAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <Eff <B> > > Go(Eff <TryOptionAsync <A> > ma, Func <A, B> f)
            {
                var ra = ma.Run();

                if (ra.IsFail)
                {
                    return(new OptionalResult <Eff <B> >(FailEff <B>(ra.Error)));
                }
                var rb = await ra.Value.Try().ConfigureAwait(false);

                if (rb.IsFaulted)
                {
                    return(new OptionalResult <Eff <B> >(rb.Exception));
                }
                if (rb.IsNone)
                {
                    return(OptionalResult <Eff <B> > .None);
                }
                return(OptionalResult <Eff <B> > .Some(SuccessEff <B>(f(rb.Value.Value))));
            }
        }
Ejemplo n.º 3
0
        public static TryOptionAsync <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, TryOptionAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <EitherUnsafe <L, B> > > Go(EitherUnsafe <L, TryOptionAsync <A> > ma, Func <A, B> f)
            {
                if (ma.IsBottom)
                {
                    return(OptionalResult <EitherUnsafe <L, B> > .Bottom);
                }
                if (ma.IsLeft)
                {
                    return(new OptionalResult <EitherUnsafe <L, B> >(LeftUnsafe <L, B>(ma.LeftValue)));
                }
                var rb = await ma.RightValue.Try().ConfigureAwait(false);

                if (rb.IsFaulted)
                {
                    return(new OptionalResult <EitherUnsafe <L, B> >(rb.Exception));
                }
                if (rb.IsNone)
                {
                    return(OptionalResult <EitherUnsafe <L, B> > .None);
                }
                return(OptionalResult <EitherUnsafe <L, B> > .Some(f(rb.Value.Value)));
            }
        }
Ejemplo n.º 4
0
        public static TryOptionAsync <Validation <Fail, B> > Traverse <Fail, A, B>(this Validation <Fail, TryOptionAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <Validation <Fail, B> > > Go(Validation <Fail, TryOptionAsync <A> > ma, Func <A, B> f)
            {
                if (ma.IsFail)
                {
                    return(new OptionalResult <Validation <Fail, B> >(Fail <Fail, B>(ma.FailValue)));
                }
                var rb = await ma.SuccessValue.Try().ConfigureAwait(false);

                if (rb.IsFaulted)
                {
                    return(new OptionalResult <Validation <Fail, B> >(rb.Exception));
                }
                if (rb.IsNone)
                {
                    return(OptionalResult <Validation <Fail, B> > .None);
                }
                return(OptionalResult <Validation <Fail, B> > .Some(f(rb.Value.Value)));
            }
        }
Ejemplo n.º 5
0
        public static TryOptionAsync <OptionUnsafe <B> > Traverse <A, B>(this OptionUnsafe <TryOptionAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <OptionUnsafe <B> > > Go(OptionUnsafe <TryOptionAsync <A> > ma, Func <A, B> f)
            {
                if (ma.IsNone)
                {
                    return(OptionalResult <OptionUnsafe <B> > .Some(OptionUnsafe <B> .None));
                }
                var rb = await ma.Value.Try().ConfigureAwait(false);

                if (rb.IsFaulted)
                {
                    return(new OptionalResult <OptionUnsafe <B> >(rb.Exception));
                }
                if (rb.IsNone)
                {
                    return(OptionalResult <OptionUnsafe <B> > .None);
                }
                return(OptionalResult <OptionUnsafe <B> > .Some(OptionUnsafe <B> .Some(f(rb.Value.Value))));
            }
        }
Ejemplo n.º 6
0
        public static TryOptionAsync <Identity <B> > Traverse <A, B>(this Identity <TryOptionAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <Identity <B> > > Go(Identity <TryOptionAsync <A> > ma, Func <A, B> f)
            {
                if (ma.IsBottom)
                {
                    return(OptionalResult <Identity <B> > .Bottom);
                }
                var rb = await ma.Value.Try();

                if (rb.IsFaulted)
                {
                    return(new OptionalResult <Identity <B> >(rb.Exception));
                }
                if (rb.IsNone)
                {
                    return(OptionalResult <Identity <B> > .None);
                }
                return(OptionalResult <Identity <B> > .Some(new Identity <B>(f(rb.Value.Value))));
            }
        }
Ejemplo n.º 7
0
        public static TryOptionAsync <Validation <MonoidFail, Fail, B> > Traverse <MonoidFail, Fail, A, B>(this Validation <MonoidFail, Fail, TryOptionAsync <A> > ma, Func <A, B> f)
            where MonoidFail : struct, Monoid <Fail>, Eq <Fail>
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <Validation <MonoidFail, Fail, B> > > Go(Validation <MonoidFail, Fail, TryOptionAsync <A> > ma, Func <A, B> f)
            {
                if (ma.IsFail)
                {
                    return(new OptionalResult <Validation <MonoidFail, Fail, B> >(Fail <MonoidFail, Fail, B>(ma.FailValue)));
                }
                var rb = await ma.SuccessValue.Try();

                if (rb.IsFaulted)
                {
                    return(new OptionalResult <Validation <MonoidFail, Fail, B> >(rb.Exception));
                }
                if (rb.IsNone)
                {
                    return(OptionalResult <Validation <MonoidFail, Fail, B> > .None);
                }
                return(OptionalResult <Validation <MonoidFail, Fail, B> > .Some(f(rb.Value.Value)));
            }
        }
Ejemplo n.º 8
0
 public int CompareTo(OptionalResult <A> other) =>
 default(OrdOptionalResult <A>).Compare(this, other);
Ejemplo n.º 9
0
 public bool Equals(OptionalResult <A> other) =>
 default(EqOptionalResult <A>).Equals(this, other);
Ejemplo n.º 10
0
 public bool Equals(OptionalResult <A> other) =>
 IsBottom == other.IsBottom &&
 IsFaulted
         ? Exception == other.Exception
         : equals <EqDefault <A>, A>(Value, other.Value);