Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal]: Deconstruction in from and let #8875

Open
MadsTorgersen opened this issue Dec 12, 2024 · 0 comments
Open

[Proposal]: Deconstruction in from and let #8875

MadsTorgersen opened this issue Dec 12, 2024 · 0 comments
Assignees
Milestone

Comments

@MadsTorgersen
Copy link
Contributor

Deconstruction in from and let

Summary

We only were able to implement P0 deconstruction scenarios in C# 7, which leaves a number of candidates unaddressed (let clause, from clause, lambda, method declaration, using, outvar, join clause, query continuation clause, join into clause, catch).

The first three in particular could use further investigation.

From clause

Instead of:

(int, int)[] tuples = new[] { (1, 2), (3, 4) };
var query = from t in tuples
        select t.Item1;

Allow:

var query = from (x, y) in tuples
        select x;

Let clause

var query = from deconstructable in deconstructables
        let (x, y) = deconstructable
        ...;

Lambda

Instead of:

tuples.Select(t => t.Item1 + t.Item2);

Allow:

tuples.Select((var (x, y)) => x + y); 
// the lambda takes one argument that is not named 
// and can be broken into two parts

Or maybe this syntax instead:

tuples.Select(((x, y)) => x +y); // same number of parentheses, but denser

Design meetings

https://github.com/dotnet/csharplang/blob/main/meetings/2016/LDM-2016-12-07-14.md#deconstruction

@MadsTorgersen MadsTorgersen added this to the Any Time milestone Dec 12, 2024
@dotnet dotnet locked and limited conversation to collaborators Dec 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants