using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Wabbajack.Common { public static class IAsyncEnumerableExtensions { /// /// Same as .Select but expects a function that returns an async result /// /// /// /// /// /// public static async IAsyncEnumerable SelectAsync(this IEnumerable coll, Func> mapFn) { foreach (var itm in coll) { yield return await mapFn(itm); } } /// /// Same as .Select but expects a function that returns an async result /// /// /// /// /// /// public static async ValueTask DoAsync(this IEnumerable coll, Func> mapFn) { foreach (var itm in coll) { await mapFn(itm); } } public static async ValueTask> ToList(this IAsyncEnumerable coll) { var list =new List(); await foreach (var itm in coll) list.Add(itm); return list; } } }