using System; namespace MemoryPools.Collections.Linq { public static partial class PoolingEnumerable { public static bool Any(this IPoolingEnumerable source) { var enumerator = source.GetEnumerator(); var hasItems = enumerator.MoveNext(); enumerator.Dispose(); return hasItems; } public static bool Any(this IPoolingEnumerable source, Func condition) { var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { if (condition(enumerator.Current)) { enumerator.Dispose(); return true; } } enumerator.Dispose(); return false; } public static bool Any(this IPoolingEnumerable source, TContext context, Func condition) { var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { if (condition(context, enumerator.Current)) { enumerator.Dispose(); return true; } } enumerator.Dispose(); return false; } public static bool All(this IPoolingEnumerable source, Func condition) { var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { if (!condition(enumerator.Current)) { enumerator.Dispose(); return false; } } enumerator.Dispose(); return true; } public static bool All(this IPoolingEnumerable source, TContext context, Func condition) { var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { if (!condition(context, enumerator.Current)) { enumerator.Dispose(); return false; } } enumerator.Dispose(); return true; } } }