diff --git a/src/Result/Extensions/Extensions.Enumerable.cs b/src/Result/Extensions/Extensions.Enumerable.cs index b1791fb..cbaf3d8 100644 --- a/src/Result/Extensions/Extensions.Enumerable.cs +++ b/src/Result/Extensions/Extensions.Enumerable.cs @@ -34,4 +34,54 @@ public static partial class Extensions return list; } + + /// + /// + /// For parallel execution of the async tasks, one should await the Task.WhenAll() of the provided list + /// before calling this function + /// + /// + // ReSharper disable once InconsistentNaming + public static async Task>> Join(this IEnumerable>> results) + { + _ = results.TryGetNonEnumeratedCount(out var count); + var list = new List(count); + + foreach (var result in results) + { + if (!(await result).TryGetValue(out var value, out var error)) + { + return new Result>(error); + } + + list.Add(value); + } + + return list; + } + + /// + /// + /// For parallel execution of the async tasks, one should await the Task.WhenAll() of the provided list + /// before calling this function + /// + /// + // ReSharper disable once InconsistentNaming + public static async ValueTask>> Join(this IEnumerable>> results) + { + _ = results.TryGetNonEnumeratedCount(out var count); + var list = new List(count); + + foreach (var result in results) + { + if (!(await result).TryGetValue(out var value, out var error)) + { + return new Result>(error); + } + + list.Add(value); + } + + return list; + } } \ No newline at end of file