/// <summary>Performs an action on each of the elements contained in the collection.</summary> /// <typeparam name="T">The type of the elements that are contained in the collection.</typeparam> /// <param name="source">The source collection.</param> /// <param name="action">The action to perform on each of the elements.</param> public static void ForEach <T>(this IEnumerable <T> source, IndexedEnumeratedElementAction <T> action) { foreach (var(index, e) in source.WithIndex()) { action(index, e); } }
/// <summary>Performs an action on each of the elements contained in the collection.</summary> /// <typeparam name="T">The type of the elements that are contained in the collection.</typeparam> /// <param name="source">The source collection.</param> /// <param name="action">The action to perform on each of the elements.</param> public static async Task ForEachAsync <T>(this IAsyncEnumerable <T> source, IndexedEnumeratedElementAction <T> action) { int index = 0; await foreach (T e in source) { action(index, e); index++; } }