-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add ofNull and toNull to ValueOption #495
Conversation
a200a9d
to
942f30e
Compare
ValueOption.ofNull
and toNull
Commit 942f30e is a refactor of what you originally shared. After posting this comment, I will force push a commit that adds the Can your code in your other PR that makes use of |
942f30e
to
1417533
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes make the build work.
@TysonMN The whole point of this construct is to not have the type constraint (see PR description). It becomes The reason we need something like this is because we need to support view model getters that work with both a nullable type or a non-nullable type, and there are certain cases where we know the type will be nullable (submodel) and we need control in elmish over whether it's null or not (especially submodelwin). |
@TysonMN also ValueOption.toNullable already exists in FSharpCore (as well as ofNullable). That's why I used |
bbb2b97
to
79dc28e
Compare
I see that now. Sorry I missed that before. |
bb2c718
to
dcd3c5a
Compare
dcd3c5a
to
019d50a
Compare
019d50a
to
314fa78
Compare
314fa78
to
357c88c
Compare
The force push I just did mostly cleans up the code. I deleted one test for |
Great work on this @marner2! I am very happy with the final implementation. I think the effort we put into this PR was worth it :) |
Add some helpers that allow for converting between
ValueOption
and nullable values without requiring that'a
be statically restrained as a nullable type.toNull
will never generateValueNone
if the value is not nullable, andofNull
will throw an exception if you feed it aValueNone
when'a
is a non-nullable value.I'm doing it unchecked currently, but I don't know of any way to match/discriminate on a type between nullable and non-nullable. I'm pretty sure you always end up with the type parameter being constrained all the way up, or not able to call constrained functions (hence why the implementation has to use boxing).