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

The Deconstruct method should optionally return Boolean #35458

Closed
igor-tkachev opened this issue May 2, 2019 · 2 comments
Closed

The Deconstruct method should optionally return Boolean #35458

igor-tkachev opened this issue May 2, 2019 · 2 comments

Comments

@igor-tkachev
Copy link

Fir example:

public static bool Deconstruct<T>(this T[] arr, out T item0, out T item1)
{
    if (arr.Length != 2)
    {
        item0 = item1 = default; // ref parameters would be useful here, no need to initialize out parameters
        return false;
    }

    item0 = arr[0];
    item1 = arr[1];

    return true;
}

Actually, it can be more then just Boolean. It be can some IDeconstructionResult, but at least Boolean can be really useful.

@CyrusNajmabadi
Copy link
Member

This is what's know as an active pattern. It's already been proposed and closed.

@jcouv
Copy link
Member

jcouv commented May 6, 2019

Please bring this discussion to the csharplang repro, where language changes are discussed (as opposed to implementation bugs of the compiler with regards to the current language design).
I'll go ahead and close this issue.

Tagging @gafter as FYI, since he's the driver for various patterns features.

@jcouv jcouv closed this as completed May 6, 2019
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

3 participants