Add ToImmutable*Async extension methods to System.Linq.Async
- Dominant language
- C#
- Stars
- 7.2k
- Forks
- 798
- PR merge metrics
- No merged PRs in 30d
Description
I would like to propose the addition of new extension methods that allow collecting an `IAsyncEnumerable` into the immutable collections from `System.Collections.Immutable`.
The overloads below are copied from `System.Collections.Immutable` with a few changes to make them async friendly.
* Add `Async` suffix
* Change return type to `ValueTask`
* Add `CancellationToken` parameter
```cs
public static ValueTask> ToImmutableArrayAsync(this IAsyncEnumerable source, CancellationToken cancellationToken = default);
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? keyComparer, IEqualityComparer? valueComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? keyComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable source, Func keySelector, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? keyComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable> source, IEqualityComparer? keyComparer, IEqualityComparer? valueComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable> source, IEqualityComparer? keyComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableDictionaryAsync(this IAsyncEnumerable> source, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableHashSetAsync(this IAsyncEnumerable source, IEqualityComparer? equalityComparer, CancellationToken cancellationToken = default);
public static ValueTask> ToImmutableHashSetAsync(this IAsyncEnumerable source, CancellationToken cancellationToken = default);
public static ValueTask> ToImmutableListAsync(this IAsyncEnumerable source, CancellationToken cancellationToken = default);
public static ValueTask> ToImmutableSortedDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IComparer? keyComparer, IEqualityComparer? valueComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableSortedDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IComparer? keyComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableSortedDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableSortedDictionaryAsync(this IAsyncEnumerable> source, IComparer? keyComparer, IEqualityComparer? valueComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableSortedDictionaryAsync(this IAsyncEnumerable> source, IComparer? keyComparer, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableSortedDictionaryAsync(this IAsyncEnumerable> source, CancellationToken cancellationToken = default) where TKey : notnull;
public static ValueTask> ToImmutableSortedSetAsync(this IAsyncEnumerable source, IComparer? comparer, CancellationToken cancellationToken = default);
public static ValueTask> ToImmutableSortedSetAsync(this IAsyncEnumerable source, CancellationToken cancellationToken = default);
```
## Pros/Cons
* Pro: Feature parity with the extensions available in the .NET SDK.
* Con: Requires a new NuGet dependency for older target frameworks because they don't include `System.Collections.Immutable`.
* others?
I'd happily create a PR for this feature.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.