Example #1
0
 /// <summary>Accumulates maximal value.</summary>
 public static IAccumulator <T?, T> MaxAccumulator <T>(CmpF <T> cmpF)
     where T : struct
 {
     return(new SimpleAccumulator <T>((T a, T b) => {
         if (cmpF(a, b) == CmpRes.LT)
         {
             return b;
         }
         else
         {
             return a;
         }
     }));
 }
Example #2
0
        /// <summary>Evaluate the maximum of arguments.</summary>
        public static T Max <T>(CmpF <T> cmpF, params T[] args)
        {
            Assert.Validate(args.Length > 0, "Min must have at least one arg");
            T max = args[0];

            for (int i = 1; i < args.Length; i++)
            {
                if (cmpF(args[i], max) == CmpRes.GT)
                {
                    max = args[i];
                }
            }
            return(max);
        }
Example #3
0
 /// <summary>Inverts the comparsion function.</summary>
 public static CmpF <T> Invert <T>(CmpF <T> cmpF)
 {
     return((T a, T b) => Invert(cmpF(a, b)));
 }
Example #4
0
 /// <summary>Gives the equivalence test function based on the given comparison function.</summary>
 public static EqF <T> EqByCmp <T>(CmpF <T> cmpF)
 {
     return((T a, T b) => cmpF(a, b) == CmpRes.EQ);
 }