You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some times we just want to do something given a specific union value, rather than handling all cases explicitly. This is most useful on larger unions.
For example consider the following code:
[Union]publicpartialrecordstruct MathResult<T>:where T :INumber<T>{publicpartialrecordstructInfinity;publicpartialrecordstructSuccess(TValue);publicpartialrecordstructNaN;publicpartialrecordstructUndefined;}MathResult<double> result =// Some complex math calculation.
Some ways we might want to interact with result
With a dedicated Match method for each case?
// A `MatchX()` is generated for each member `X` of the union. You must provide an else case.varvalue= result.MatchSuccess(// If `Infinity, NaN, or Undefined` return 0.()=>0);
Perhaps a more imperative, idiomatic C# way?
// A `TryGetX` is generated for each member `X` of the union.if(result.TryGetSuccess(outvar success)){
Console.WriteLine(success.Value);}
The text was updated successfully, but these errors were encountered:
Some times we just want to do something given a specific union value, rather than handling all cases explicitly. This is most useful on larger unions.
For example consider the following code:
Some ways we might want to interact with
result
Match
method for each case?The text was updated successfully, but these errors were encountered: