Feature request: coalesce operator to work with tuples' values #2390
Replies: 4 comments
-
Looking at the syntax my instinct would say that the NCO would be hit in an OR manner. For the behaviour you're describing, I think it should be written as (a, b) = (c ?? "foo", d ?? "bar");
// Which is then essentially
a = c ?? "foo", b = d ?? "bar"; |
Beta Was this translation helpful? Give feedback.
-
I think my main problem with this proposal is that it would be confusing. Consider the following two methods: (string, string) M1((string, string)? t1, (string, string) t2) => t1 ?? t2;
(string, string) M2((string, string) t1, (string, string) t2) => t1 ?? t2; Those two methods are quite similar, but behave very differently, and I think that would lead to confusion. |
Beta Was this translation helpful? Give feedback.
-
Your syntax really makes a lot more sense and right now I see how bad my syntax would be and how much code smell could be created with it. |
Beta Was this translation helpful? Give feedback.
-
That was exactly my first instinct. Given the grouping nature of tuples, it makes more sense this way and doing it the other way would be inconsistent. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Make it so that the coalesce operator can check and assign values inside tuples based on values inside other tuples value-by-value.
Ex.:
Would produce
a == "c"
andb == "bar"
, that is: the operator checks for value insidec
, which isn't null, and assigns it toa
; it then checks value insided
, which is null, and assigns"bar"
tob
.Beta Was this translation helpful? Give feedback.
All reactions