-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A non-exception Value<T> alternative for unions #49
Comments
Closed
DavidArno
added a commit
that referenced
this issue
Nov 26, 2018
Added TryGetValue() methods to the union types. These return the value as a Option<T>.Some, or OPtion<T>.None if the type doesn't match any of the union cases.
DavidArno
added a commit
that referenced
this issue
Nov 26, 2018
Putting a checklist here to keep track of adding this to the new v4:
|
DavidArno
added a commit
that referenced
this issue
Sep 9, 2019
Need to add details of these methods to the wiki now that v4 is released. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to be able to get the Value of a union using the syntax of Value() (i.e. using the class name), but without the risk of throwing an exception. I have 3 approaches in mind, and before I start coding I was hoping you could weigh in on which way I should go.
Option<T> GetValue<T>()
which returns Some if the union is of type T, else Nonebool TryGetValue<T>(out value)
which returns a bool as to whether it succeeded and the actual value in the out parambool HasValue<T>()
which just returns a bool for whether this union is of type TDo you have a preferred approach?
Thank you,
Gavin Steyn
The text was updated successfully, but these errors were encountered: