[Proposal] switch expression as function #2284
Replies: 4 comments
-
If #91 were implement then theoretically you could do: var area = shapes.Sum(@ switch {
Rect r => r.width * r.height,
Circle c => c.d * Math.Pi,
}); |
Beta Was this translation helpful? Give feedback.
-
Thank you. Yes, it is close, but a bit different. I've thought a bit more about my proposal and it is transforming into the more general one but more complicated as well:
So to say, Then "magically", instead of writing
you can write
And it just works, assuming that there is no order or employee defined in the scope. |
Beta Was this translation helpful? Give feedback.
-
Re: original suggestion: too specific IMHO, better to solve via #91. Keep the suggestions coming! |
Beta Was this translation helpful? Give feedback.
-
Thank you for comment.
Yes, it is more specific than #91, but due to its specific it might be still implemented if #91 gets rejected. BTW, I've remembered that it exists in F# - it is pattern matching function.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following case:
the
s => s
seems redundant here. It would be a bit simpler to haveThe
switch { ... }
in the functional context could be resolved toFunc<T, V>
.Similar concept exists in F# - it is pattern matching function:
Beta Was this translation helpful? Give feedback.
All reactions