I am wondering what rules exist to determine if a portion of LINQ code suffers from double enumeration?
For example, what are the telltale signs that the following code might be a double enumeration? What are some other signs to look for?
public static bool MyIsIncreasingMonotonicallyBy<T, TResult>(this IEnumerable<T> list, Func<T, TResult> selector) where TResult : IComparable<TResult> { return list.Zip(list.Skip(1), (a, b) => selector(a).CompareTo(selector(b)) <= 0).All(b => b); }
source share