예제 #1
0
 /// <summary>
 /// Equals
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(AccResult <TSuccess, TFailure> other)
 {
     if (index == null && other.index == null)
     {
         return(true);
     }
     if (index == null || other.index == null)
     {
         return(false);
     }
     if (IsSuccess)
     {
         return(other.Equals(AsSuccess));
     }
     if (IsFailure)
     {
         return(other.Equals(AsFailure));
     }
     return(false);
 }
예제 #2
0
        /// <summary>
        /// if either are failures, result is combined failure, else run the func on the success value
        /// </summary>
        /// <typeparam name="TSuccess2"></typeparam>
        /// <param name="e1"></param>
        /// <param name="e2"></param>
        /// <returns></returns>
        public static AccResult <TSuccess2, TFailure> Apply <TSuccess2>(AccResult <Func <TSuccess, TSuccess2>, TFailure> e1, AccResult <TSuccess, TFailure> e2)
        {
            e1.CheckIndex();
            e2.CheckIndex();

            if (e1.IsFailure && e2.IsFailure)
            {
                return(e1.AsFailure.Concat(e2.AsFailure).ToList());
            }
            else if (e1.IsFailure && e2.IsSuccess)
            {
                return(e1.AsFailure);
            }
            else if (e1.IsSuccess && e2.IsFailure)
            {
                return(e2.AsFailure);
            }

            return(e1.AsSuccess(e2.AsSuccess));
        }
예제 #3
0
 /// <summary>
 /// lift a 4-argument function over 4 AccResults.  (If all AccResults are IsSuccess, apply the function to the success values; else results in Failure)
 /// </summary>
 public static AccResult <E, Z> LiftA4 <A, B, C, D, E, Z>(Func <A, B, C, D, E> f, AccResult <A, Z> a, AccResult <B, Z> b, AccResult <C, Z> c, AccResult <D, Z> d)
 {
     return(a.Map(f.Curry()).Apply(b).Apply(c).Apply(d));
 }
예제 #4
0
 /// <summary>
 /// lift a 3-argument function over 3 AccResults.  (If all AccResults are IsSuccess, apply the function to the success values; else results in Failure)
 /// </summary>
 public static AccResult <D, Z> LiftA3 <A, B, C, D, Z>(Func <A, B, C, D> f, AccResult <A, Z> a, AccResult <B, Z> b, AccResult <C, Z> c)
 {
     return(a.Map(f.Curry()).Apply(b).Apply(c));
 }
예제 #5
0
 /// <summary>
 /// lift a 2-argument function over 2 AccResults.  (If all AccResults are IsSuccess, apply the function to the success values; else results in Failure)
 /// </summary>
 public static AccResult <C, Z> LiftA2 <A, B, C, Z>(Func <A, B, C> f, AccResult <A, Z> a, AccResult <B, Z> b)
 {
     return(a.Map(f.Curry()).Apply(b));
 }
예제 #6
0
 /// <summary>
 /// if either are failures, result is combined failure; else run the func else run the func on the success value
 /// </summary>
 public static AccResult <TSuccess2, TFailure> Apply <TSuccess, TSuccess2, TFailure>(this AccResult <Func <TSuccess, TSuccess2>, TFailure> e1, AccResult <TSuccess, TFailure> e2)
 {
     return(AccResult <TSuccess, TFailure> .Apply(e1, e2));
 }