/// <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);
/// <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);
public static IEnumerable <Validation <Fail, B> > Sequence <Fail, A, B>(this Validation <Fail, A> ma, Func <A, IEnumerable <B> > f) => ma.Map(f).Sequence();
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);
public static HashSet <Validation <FAIL, B> > Sequence <FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, HashSet <B> > f) => ta.Map(f).Sequence();
public static ValueTask <Validation <FAIL, A> > Sequence <FAIL, A>(this Validation <FAIL, ValueTask <A> > ta) => ta.Traverse(identity);
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);
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));
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);
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();
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();
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);
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();
/// <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));
public Validation <MonoidFail, FAIL, U> Bind <U>(Func <SUCCESS, Validation <MonoidFail, FAIL, U> > f) => IsSuccess ? f(success) : Validation <MonoidFail, FAIL, U> .Fail(FailValue);
/// <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);
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))); } }
public static EitherAsync <L, Validation <FAIL, A> > Sequence <FAIL, L, A>(this Validation <FAIL, EitherAsync <L, A> > ta) => ta.Traverse(identity);
public static HashSet <Validation <FAIL, A> > Sequence <FAIL, A>(this Validation <FAIL, HashSet <A> > ta) => ta.Traverse(identity);
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);
public static Aff <Validation <FAIL, A> > Sequence <FAIL, A>(this Validation <FAIL, Aff <A> > ta) => ta.Traverse(identity);
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();
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);
public static Arr <Validation <FAIL, B> > Sequence <FAIL, A, B>(this Validation <FAIL, A> ta, Func <A, Arr <B> > f) => ta.Map(f).Sequence();