Example #1
0
 /// <summary>
 /// Represents a successful operation
 /// </summary>
 /// <typeparam name="ERROR">Error type</typeparam>
 /// <typeparam name="A">Value type</typeparam>
 /// <param name="value">Value</param>
 /// <returns>Validation applicative</returns>
 public static Validation <ERROR, A> Success <ERROR, A>(A value) =>
 Validation <ERROR, A> .Success(value);
Example #2
0
 /// <summary>
 /// Represents a successful operation
 /// </summary>
 /// <typeparam name="MonoidError">Monoid for collecting the errors</typeparam>
 /// <typeparam name="ERROR">Error type</typeparam>
 /// <typeparam name="A">Value type</typeparam>
 /// <param name="value">Value</param>
 /// <returns>Validation applicative</returns>
 public static Validation <MonoidError, ERROR, A> Success <MonoidError, ERROR, A>(A value)
     where MonoidError : struct, Monoid <ERROR>, Eq <ERROR> =>
 Validation <MonoidError, ERROR, A> .Success(value);
Example #3
0
 public static IEnumerable <Validation <Fail, B> > Sequence <Fail, A, B>(this Validation <Fail, A> ma, Func <A, IEnumerable <B> > f) =>
 ma.Map(f).Sequence();
Example #4
0
 public static Validation <MonoidFail, Fail, Validation <MonoidFail, Fail, B> > Sequence <MonoidFail, Fail, A, B>(this Validation <MonoidFail, Fail, A> ta, Func <A, Validation <MonoidFail, Fail, B> > f)
     where MonoidFail : struct, Monoid <Fail>, Eq <Fail> =>
 ta.Map(f).Traverse(Prelude.identity);
Example #5
0
 public static HashSet <Validation <FAIL, B> > Sequence <FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, HashSet <B> > f) =>
 ta.Map(f).Sequence();
Example #6
0
 public static ValueTask <Validation <FAIL, A> > Sequence <FAIL, A>(this Validation <FAIL, ValueTask <A> > ta) =>
 ta.Traverse(identity);
Example #7
0
 public static Stck <Validation <FAIL, B> > Sequence <FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, Stck <B> > f) =>
 ta.Map(f).Traverse(Prelude.identity);
Example #8
0
 public static Validation <MonoidFail, FAIL, R> Apply <MonoidFail, FAIL, A, R>(this ValueTuple <Validation <MonoidFail, FAIL, A> > items, Func <A, R> f)
     where MonoidFail : struct, Monoid <FAIL>, Eq <FAIL> =>
 items.Item1.Match(
     Succ : s => f(s),
     Fail : e => Validation <MonoidFail, FAIL, R> .Fail(e));
Example #9
0
 public static Aff <RT, Validation <MonoidFail, FAIL, A> > Sequence <RT, MonoidFail, FAIL, A>(this Validation <MonoidFail, FAIL, Aff <RT, A> > mma)
     where MonoidFail : struct, Monoid <FAIL>, Eq <FAIL>
     where RT : struct, HasCancel <RT> =>
 mma.Traverse(identity);
Example #10
0
 public static Aff <RT, Validation <MonoidFail, FAIL, B> > Sequence <RT, MonoidFail, FAIL, A, B>(this Validation <MonoidFail, FAIL, A> ta, Func <A, Aff <RT, B> > f)
     where MonoidFail : struct, Monoid <FAIL>, Eq <FAIL>
     where RT : struct, HasCancel <RT> =>
 ta.Map(f).Sequence();
Example #11
0
 public static Aff <RT, Validation <FAIL, B> > Sequence <RT, FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, Aff <RT, B> > f)
     where RT : struct, HasCancel <RT> =>
 ta.Map(f).Sequence();
Example #12
0
 public static Aff <RT, Validation <FAIL, A> > Sequence <RT, FAIL, A>(this Validation <FAIL, Aff <RT, A> > mma)
     where RT : struct, HasCancel <RT> =>
 mma.Traverse(identity);
Example #13
0
 public static Eff <RT, Validation <FAIL, B> > Sequence <RT, FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, Eff <RT, B> > f) where RT : struct =>
 ta.Map(f).Sequence();
Example #14
0
 /// <summary>
 /// Represents a failed operation
 /// </summary>
 /// <typeparam name="ERROR">Error type</typeparam>
 /// <typeparam name="A">Value type</typeparam>
 /// <param name="value">Error value</param>
 /// <returns>Validation applicative</returns>
 public static Validation <ERROR, A> Fail <ERROR, A>(ERROR value) =>
 Validation <ERROR, A> .Fail(Seq1(value));
Example #15
0
 public Validation <MonoidFail, FAIL, U> Bind <U>(Func <SUCCESS, Validation <MonoidFail, FAIL, U> > f) =>
 IsSuccess
         ? f(success)
         : Validation <MonoidFail, FAIL, U> .Fail(FailValue);
Example #16
0
 /// <summary>
 /// Represents a failed operation
 /// </summary>
 /// <typeparam name="MonoidError">Monoid for collecting the errors</typeparam>
 /// <typeparam name="ERROR">Error type</typeparam>
 /// <typeparam name="A">Value type</typeparam>
 /// <param name="value">Error value</param>
 /// <returns>Validation applicative</returns>
 public static Validation <MonoidError, ERROR, A> Fail <MonoidError, ERROR, A>(ERROR value)
     where MonoidError : struct, Monoid <ERROR>, Eq <ERROR> =>
 Validation <MonoidError, ERROR, A> .Fail(value);
Example #17
0
        public static TryAsync <Validation <MonoidFail, Fail, B> > Traverse <MonoidFail, Fail, A, B>(this Validation <MonoidFail, Fail, TryAsync <A> > ma, Func <A, B> f)
            where MonoidFail : struct, Monoid <Fail>, Eq <Fail>
        {
            return(ToTry(() => Go(ma, f)));

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

                if (rb.IsFaulted)
                {
                    return(new Result <Validation <MonoidFail, Fail, B> >(rb.Exception));
                }
                return(new Result <Validation <MonoidFail, Fail, B> >(f(rb.Value)));
            }
        }
Example #18
0
 public static EitherAsync <L, Validation <FAIL, A> > Sequence <FAIL, L, A>(this Validation <FAIL, EitherAsync <L, A> > ta) =>
 ta.Traverse(identity);
Example #19
0
 public static HashSet <Validation <FAIL, A> > Sequence <FAIL, A>(this Validation <FAIL, HashSet <A> > ta) =>
 ta.Traverse(identity);
Example #20
0
 public static HashSet <Validation <MonoidFail, FAIL, B> > Sequence <MonoidFail, FAIL, A, B>(this Validation <MonoidFail, FAIL, A> ta, Func <A, HashSet <B> > f)
     where MonoidFail : struct, Monoid <FAIL>, Eq <FAIL> =>
 ta.Map(f).Traverse(Prelude.identity);
Example #21
0
 public static Aff <Validation <FAIL, A> > Sequence <FAIL, A>(this Validation <FAIL, Aff <A> > ta) =>
 ta.Traverse(identity);
Example #22
0
 public static ValueTask <Validation <MonoidFail, FAIL, A> > Sequence <MonoidFail, FAIL, A>(this Validation <MonoidFail, FAIL, ValueTask <A> > ta)
     where MonoidFail : struct, Monoid <FAIL>, Eq <FAIL> =>
 ta.Traverse(identity);
 public static TryOptionAsync <Validation <FAIL, B> > Sequence <FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, TryOptionAsync <B> > f) =>
 ta.Map(f).Sequence();
Example #24
0
 public static IEnumerable <Validation <MonoidFail, Fail, B> > Sequence <MonoidFail, Fail, A, B>(this Validation <MonoidFail, Fail, A> ma, Func <A, IEnumerable <B> > f)
     where MonoidFail : struct, Monoid <Fail>, Eq <Fail> =>
 ma.Map(f).Traverse(Prelude.identity);
Example #25
0
 public static Arr <Validation <FAIL, B> > Sequence <FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, Arr <B> > f) =>
 ta.Map(f).Sequence();