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

deconstructing witin LINQ comprehensions #15074

Closed
gafter opened this issue Nov 8, 2016 · 5 comments
Closed

deconstructing witin LINQ comprehensions #15074

gafter opened this issue Nov 8, 2016 · 5 comments

Comments

@gafter
Copy link
Member

gafter commented Nov 8, 2016

It has been suggested that we support

from (a, b) in Pairs select a * b

from t in Pairs let (a, b) = t select a * b
@HaloFour
Copy link

HaloFour commented Nov 8, 2016

Feels like a good first step towards #6877, starting with compiler-verified guaranteed to succeed tuple patterns.

@jamesqo
Copy link
Contributor

jamesqo commented Nov 9, 2016

Definitely seems like a good idea. +1

@ghost
Copy link

ghost commented Nov 15, 2016

Ufff! for a moment I believed the asterisk (in the second example) represented an F-Sharpesque tuple style.

@atifaziz
Copy link
Contributor

While we anxiously wait for this to appear in a future version of C#, one could deconstruct via a folding function for tuples, like this:

static class TupleExtensions
{
    public static TResult Fold<T1, T2, TResult>(this (T1, T2) tuple, Func<T1, T2, TResult> folder) =>
        folder(tuple.Item1, tuple.Item2);
}

and then use it in LINQ as follows:

from t in Pairs select t.Fold((a, b) => a * b);

@jcouv
Copy link
Member

jcouv commented Sep 5, 2017

This language feature requests is tracked by dotnet/csharplang#189
I'll go ahead and close this Roslyn issue. Thanks

@jcouv jcouv closed this as completed Sep 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants