using System; using System.Collections.Generic; namespace JM.LinqFaster { public static partial class LinqFaster { // -------------------------- ARRAYS -------------------------------------------- /// /// Determines whether an array contains any elements /// /// The array to check for emptiness /// true if the source array contains any elements, otherwise, false/ public static bool AnyF(this T[] source) { if (source == null) { throw Error.ArgumentNull("source"); } return source.Length > 0; } /// /// Determines whether any element of an array satifies a condition. /// /// An array whose elements to apply the predicate to. /// A function to test each element for a condition. /// true if any elements in the source array pass the test in the specified predicate; otherwise, false. public static bool AnyF(this TSource[] source, Predicate predicate) { if (source == null) { throw Error.ArgumentNull("source"); } if (predicate == null) { throw Error.ArgumentNull("predicate"); } return Array.Exists(source, predicate); } /// /// Determines whether all elements of an array satisfy a condition. /// /// An array that contains the elements to apply the predicate to. /// A function to test each element for a condition. /// true if every element of the source array passes the test in the specified /// predicate, or if the array is empty; otherwise, false public static bool AllF(this TSource[] source, Predicate predicate) { if (source == null) { throw Error.ArgumentNull("source"); } if (predicate == null) { throw Error.ArgumentNull("predicate"); } return Array.TrueForAll(source, predicate); } // -------------------------- Lists -------------------------------------------- /// /// Determines whether a list contains any elements /// /// The list to check for emptiness /// true if the source list contains any elements, otherwise, false/ public static bool AnyF(this List source) { if (source == null) { throw Error.ArgumentNull("source"); } return source.Count > 0; } /// /// Determines whether any element of an array satifies a condition. /// /// An array whose elements to apply the predicate to. /// A function to test each element for a condition. /// true if any elements in the source array pass the test in the specified predicate; otherwise, false. public static bool AnyF(this List source, Predicate predicate) { if (source == null) { throw Error.ArgumentNull("source"); } if (predicate == null) { throw Error.ArgumentNull("predicate"); } return source.Exists(predicate); } /// /// Determines whether all elements of a list satisfy a condition. /// /// A list that contains the elements to apply the predicate to. /// A function to test each element for a condition. /// true if every element of the source array passes the test in the specified /// predicate, or if the list is empty; otherwise, false public static bool AllF(this List source, Predicate predicate) { if (source == null) { throw Error.ArgumentNull("source"); } if (predicate == null) { throw Error.ArgumentNull("predicate"); } return source.TrueForAll(predicate); } } }