public static Try <Validation <Fail, B> > Traverse <Fail, A, B>(this Validation <Fail, Try <A> > ma, Func <A, B> f) => () => { if (ma.IsFail) { return(new Result <Validation <Fail, B> >(Fail <Fail, B>(ma.FailValue))); } else { var mr = ma.SuccessValue(); if (mr.IsBottom) { return(new Result <Validation <Fail, B> >(BottomException.Default)); } if (mr.IsFaulted) { return(new Result <Validation <Fail, B> >(mr.Exception)); } return(new Result <Validation <Fail, B> >(Validation <Fail, B> .Success(f(mr.Value)))); } };
public static TryOption <Validation <MonoidFail, Fail, B> > Traverse <MonoidFail, Fail, A, B>( this Validation <MonoidFail, Fail, TryOption <A> > ma, Func <A, B> f) where MonoidFail : struct, Monoid <Fail>, Eq <Fail> => () => { if (ma.IsFail) { return(new OptionalResult <Validation <MonoidFail, Fail, B> >(Fail <MonoidFail, Fail, B>(ma.FailValue))); } var mr = ma.SuccessValue(); if (mr.IsBottom) { return(new OptionalResult <Validation <MonoidFail, Fail, B> >(BottomException.Default)); } if (mr.IsFaulted) { return(new OptionalResult <Validation <MonoidFail, Fail, B> >(mr.Exception)); } if (mr.IsNone) { return(OptionalResult <Validation <MonoidFail, Fail, B> > .None); } return(new OptionalResult <Validation <MonoidFail, Fail, B> >(Validation <MonoidFail, Fail, B> .Success(f(mr.Value.Value)))); };