Replies: 1 comment
-
Yeah, it would be nice, but only as long as the behavior of This solution looks good, though? return switch
{
{ HasNoValue: true } => "a",
{ Value: "X" } => "b"
} This is the same as: if (maybe.HasNoValue)
return "a";
if (maybe.Value == "X")
return "b"; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@vkhorikov today at work, one of my colleague used a switch expression on a maybe.
and he used it via the Property Pattern matching and not the positional pattern + deconstruct.
it looked something like this:
and because of the current implementation of the Value property is was breaking as expected
so every time you wish you use switch expression with property matching it would fail if you try to switch on the Value property value.
so the only way to use a switch expression with the Maybe type is via the positional pattern matching that uses the deconstruct like this
or
with the Property Matching with some ordering like this, to validate the HasValue first
or be robust upfront with a If, or use some safety execution extension like the Maybe.Execute
so i was thinking, okay i'll push some changes, to simply return the _value instead of GetValueOrThrow but that's a massive breaking change.
It would be nice to have support that feature out of the box, but it implies a huge behaviour change.
Beta Was this translation helpful? Give feedback.
All reactions