|
|
|
|
|
by sbelskie
1048 days ago
|
|
FWIW, this a switch expression rather than a switch statement. But in any case I really love this addition to the language but the inability to have multi-line or block expression arms is a constant annoyance for me. You can even combine these with the new one line record syntax to create a poor man’s discriminated union. |
|
The workaround for that is the same as the workaround for the really lame one line limitation: you need to call a (preferably (static) local) function in the handler portion and then return something like `true` assigned to a discard. Hacks all around!
Eg
_ = foo switch a when … => CaseA(foo), _ => CaseB(foo);
With CaseA and CaseB returning bool in order to call a function depending on the value of foo rather than assign a value.