[Proposal]: Iterators in lambdas
Open
@jaredpar is already working on this.
Since Jun 20, 2025.
Proposal champion
- Dominant language
- C#
- Stars
- 12.7k
- Forks
- 1.1k
- Avg merge
- 11h 1m
- Merged PRs (30d)
- 3
Description
Iterators in lambdas
- Specification: https://github.com/dotnet/csharplang/blob/main/proposals/iterators-in-lambdas.md
- Discussion: https://github.com/dotnet/csharplang/discussions/9393
Summary
This proposal will remove the restriction that lambda expressions cannot be iterators.
// Desired code
app.MapGet("/search", async IAsyncEnumerable<Product>(
string query, VectorStoreCollection<int, Product> collection) =>
{
await foreach (var result in collection.SearchAsync(query, top: 5, new() { Filter = r => r.TenantId == 8 }))
{
yield return result.Record;
}
}
// Actual code
app.MapGet("/search", MapForSearch);
async IAsyncEnumerable<Product> MapForSearch(string query, VectorStoreCollection<int, Product> collection)
{
await foreach (var result in collection.SearchAsync(query, top: 5, new() { Filter = r => r.TenantId == 8 }))
{
yield return result.Record;
}
}
Design meetings
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.