dotnet / dotnet/reactive

Add IAsyncEnumerable<>.SelectAwait accetpting Func<..,Task<>>

Open
#1,528 1 comment 0 reactions 0 assignees View on GitHub
[area] Ix
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Description

I would like to suggest adding the following methods to `System.Linq.AsyncEnumerable`:

```cs
public static IAsyncEnumerable SelectAwait(
this IAsyncEnumerable source,
Func> selector);

public static IAsyncEnumerable SelectAwait(
this IAsyncEnumerable source,
Func> selector);

public static IAsyncEnumerable SelectAwaitWithCancellation(
this IAsyncEnumerable source,
Func> selector);

public static IAsyncEnumerable SelectAwaitWithCancellation(
this IAsyncEnumerable source,
Func> selector);
```

This would allow using selector functions which already return a `Task`;

I currenly have the following code:
```cs
FileList
.ToAsyncEnumerable()
.SelectAwaitWithCancellation(async (f, ct) => await File.ReadAllTextAsync(f, ct))
.Select(LoadFile);
```

If the requested overloads where added I could write is as:
```cs
FileList
.ToAsyncEnumerable()
.SelectAwaitWithCancellation(File.ReadAllTextAsync)
.Select(LoadFile);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.