private static Func <TItemToTest, bool> Combine <TItemToTest>(
            Func <TItemToTest, bool>[] innerResults,
            CombinationOperator @operator)
        {
            Func <TItemToTest, bool> AllReducer()
            => relatedItemCollection =>
            {
                for (var i = 0; i < innerResults.Length; i++)
                {
                    if (!innerResults[i](relatedItemCollection))
                    {
                        return(false);
                    }
                }

                return(true);
            };

            Func <TItemToTest, bool> AnyReducer()
            => relatedItemCollection =>
            {
                for (var i = 0; i < innerResults.Length; i++)
                {
                    if (innerResults[i](relatedItemCollection))
                    {
                        return(true);
                    }
                }

                return(false);
            };

            return(@operator.Match(AllReducer, AnyReducer));
        }
 public static TResult Match <TSource, TResult>(
     this IEnumerable <TSource> source,
     Func <IEnumerable <TSource>, TResult> allReducer,
     Func <IEnumerable <TSource>, TResult> anyReducer,
     CombinationOperator @operator = default)
 => @operator.Match(
     () => allReducer(source),
     () => anyReducer(source));
Exemplo n.º 3
0
        internal static Func <TItemToTest, bool> Combine <TItemToTest>(
            IEnumerable <Func <TItemToTest, bool> > innerResults,
            CombinationOperator @operator)
        {
            Func <TItemToTest, bool> AllReducer()
            => relatedItemCollection => innerResults.All(comparator => comparator(relatedItemCollection));

            Func <TItemToTest, bool> AnyReducer()
            => relatedItemCollection => innerResults.Any(comparator => comparator(relatedItemCollection));

            return(@operator.Match(AllReducer, AnyReducer));
        }