public static Func<dynamic> Evaluate(this Func<dynamic> unknown, Func<dynamic> fact)
        {
            if (unknown.FullMatch(fact))
                return unknown.CalculateFrom(fact);

            if (unknown.FullMatch(fact.Invert()))
                return unknown.CalculateFrom(fact.Invert());

            return null;
        }
        public static Func<dynamic> ConvertTo(this Func<dynamic> from, Func<dynamic> to)
        {
            if (from.LeftMatchesLeft(to))
                return from.ConvertRightPartToRight(to);

            if (from.LeftMatchesLeft(to.Invert()))
                return from.ConvertRightPartToRight(to.Invert());

            if (from.Invert().LeftMatchesLeft(to))
                return from.Invert().ConvertRightPartToRight(to);

            if (from.Invert().LeftMatchesLeft(to.Invert()))
                return from.Invert().ConvertRightPartToRight(to.Invert());

            return null;
        }
Example #3
0
 /// <summary>
 /// Throws exception when the predicate is satisfied.
 /// </summary>
 public static T ThrowIf <T>(this T attempt, Func <T, bool> predicate) where T : Attempt
 {
     if (attempt == null)
     {
         throw new ArgumentNullException(nameof(attempt));
     }
     if (predicate == null)
     {
         throw new ArgumentNullException(nameof(predicate));
     }
     return(attempt.CatchIf(predicate.Invert()));
 }
Example #4
0
 /// <summary>
 /// Causes failed attempts that do not satisfy the predicate to throw their exception, halting further attempts.
 /// </summary>
 public static IEnumerable <Lazy <T> > CatchWhere <T>(this IEnumerable <Lazy <T> > attempts, Func <T, bool> predicate)
     where T : Attempt
 {
     return(attempts.ThrowWhere(predicate.Invert()));
 }
Example #5
0
 public static IEnumerable <T[]> AccumulateUntil <T>(this IEnumerable <T> source,
                                                     Func <T, bool> predicate)
 {
     return(AccumulateWhile(source, predicate.Invert()));
 }
Example #6
0
 public static Delegate RemoveAll(this Delegate dlg, Func<Delegate, bool> pred)
 {
     return Delegate.Combine(dlg.GetInvocationList()
         .Where(pred.Invert())
         .ToArray());
 }