Adept icon indicating copy to clipboard operation
Adept copied to clipboard

Feature request: switch expression

Open Apis035 opened this issue 8 months ago • 3 comments

For example, if I could write this code:

rateText String

switch rate {
    case 1 rateText = "Weak"
    case 2 rateText = "Moderate"
    case 3 rateText = "Strong"
    case 4 rateText = "Powerful"
    default rateText = "Unknown"
}

Into this:

rateText String = switch rate {
    case 1 "Weak"
    case 2 "Moderate"
    case 3 "Strong"
    case 4 "Powerful"
    default "Unknown"
}

It would make the code shorter to type as rateText is only typed once. Its also much nicer to look at.

Currently, typing this switch expression makes the compiler error "unexpected switch token in expression".

Apis035 avatar Jun 19 '24 04:06 Apis035