Skip to content

Commit

Permalink
Merge pull request #75 from doomchild/feature/issue-74
Browse files Browse the repository at this point in the history
Issue-74: Return IReadOnlyList from Partition
  • Loading branch information
doomchild authored Jul 26, 2024
2 parents 91e994e + 5b9ddc5 commit b031d6f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/TaskExtras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ private static Task<T> DoRetry<T>(
/// <typeparam name="T">The underlying type of the tasks in <paramref name="tasks"/>.</typeparam>
/// <param name="tasks">The collection of tasks to partition.</param>
/// <returns>A tuple of the partitioned tasks.</returns>
public static Task<(IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled)> Partition<T>(
public static Task<(IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled)> Partition<T>(
IEnumerable<Task<T>> tasks
)
{
return tasks.Aggregate<Task<T>, Task<(IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled)>>(
Task.FromResult(((IEnumerable<Task<T>>)new List<Task<T>>(), (IEnumerable<Task<T>>)new List<Task<T>>())),
ZipTasksWith<T, (IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled), (IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled), Exception>
return tasks.Aggregate<Task<T>, Task<(IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled)>>(
Task.FromResult(((IReadOnlyList<Task<T>>)new List<Task<T>>(), (IReadOnlyList<Task<T>>)new List<Task<T>>())),
ZipTasksWith<T, (IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled), (IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled), Exception>
(
(values, v) => (values.Faulted, values.Fulfilled.Append(Task.FromResult(v)).ToList()),
(values, v) => (values.Faulted.Append<Task<T>>(Task.FromException<T>(v)).ToList(), values.Fulfilled)
Expand Down

0 comments on commit b031d6f

Please sign in to comment.