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

List pattern syntax mutation #2951

Open
richardwerkman opened this issue Jun 7, 2024 · 0 comments
Open

List pattern syntax mutation #2951

richardwerkman opened this issue Jun 7, 2024 · 0 comments
Labels
🚀 Feature request New feature or request

Comments

@richardwerkman
Copy link
Member

richardwerkman commented Jun 7, 2024

Is your feature request related to a problem? Please describe.
The following code (in the switch expression) should be mutated but is not:

    public void ListPatterns()
    {
        decimal balance = 0m;
        string[][] transactions = new[]
        {
            new[] { "1", "DEPOSIT", "100.00" },
        };
        foreach (string[] transaction in transactions)
        {
            balance += transaction switch
            {
            // "DEPOSIT" should be mutated here
            [_, "DEPOSIT", _, var amount] => decimal.Parse(amount),
            [_, "WITHDRAWAL", .., var amount] => -decimal.Parse(amount),
            [_, "INTEREST", var amount] => decimal.Parse(amount),
            [_, "FEE", var fee] => -decimal.Parse(fee),
                _ => throw new InvalidOperationException($"Record {string.Join(", ", transaction)} is not in the expected format!"),
            };
            Console.WriteLine($"Record: {string.Join(", ", transaction)}, New balance: {balance:C}");
        }
    }

Describe the solution you'd like
We should introduce a new orchestrator for the syntax type ListPatternSyntax.

@richardwerkman richardwerkman added the 🚀 Feature request New feature or request label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant