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

Switch expression as evolution of ternary operator #4118

Closed
miqm opened this issue Aug 23, 2021 · 4 comments
Closed

Switch expression as evolution of ternary operator #4118

miqm opened this issue Aug 23, 2021 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@miqm
Copy link
Collaborator

miqm commented Aug 23, 2021

Is your feature request related to a problem? Please describe.
Building complex cases when you need to check multiple conditions and decide which value to use can be very difficult (but not impossible) with ternary operator.
Lack of new line support makes it double complicated, as you cannot break lines in to make it more readable

Describe the solution you'd like
I'd like to be able to use a switch expression similar to C# 8.0 (https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/may/csharp-8-0-pattern-matching-in-csharp-8-0#the-evolution-of-pattern-matching-in-c-80)

var value = switch {
cond1 && cond2 => v1
cond1 && !cond2 => v2
cond3 => v3 //this would be evaluated only if previous steps fail to match
_ => default
}
@miqm miqm added the enhancement New feature or request label Aug 23, 2021
@ghost ghost added the Needs: Triage 🔍 label Aug 23, 2021
@slavizh
Copy link
Contributor

slavizh commented Aug 23, 2021

somehow duplicate to #448

@miqm
Copy link
Collaborator Author

miqm commented Aug 23, 2021

@slavizh Indeed, I saw that issue and thought it was for introducing a switch on resources rather than on variables or values.

@alex-frankel
Copy link
Collaborator

Going to close this as a dup of #448 for now

@miqm miqm added duplicate This issue or pull request already exists and removed enhancement New feature or request Needs: Triage 🔍 labels Sep 1, 2021
@zhoulf1006
Copy link

Is there any plan of introducing this ability?

@ghost ghost locked as resolved and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants