dotnet / dotnet/csharplang

[Proposal]: Deconstruction in from and let

Open
#8,875 0 comments 0 reactions 2 assignees Claimed by @jcouv View on GitHub
Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

# Deconstruction in from and let

* Specification: _Not added. See below._
* Discussion: https://github.com/dotnet/csharplang/discussions/8874

## Summary
[summary]: #summary

We only were able to implement P0 deconstruction scenarios in C# 7, which leaves a number of [candidates](https://github.com/dotnet/roslyn/issues/11299) 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:

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

Allow:

``` C#
var query = from (x, y) in tuples
select x;
```
### Let clause

``` C#
var query = from deconstructable in deconstructables
let (x, y) = deconstructable
...;
```
### Lambda

Instead of:

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

Allow:

``` C#
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:

``` C#
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

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.