-
Notifications
You must be signed in to change notification settings - Fork 73
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
Implicit operator for option type #9
Comments
Hi Janno, I will consider this. In general I am not a big fan of implicit conversions, and it does leave some questions to what the conversion behavior should be, e.g. should it return value.Some() or maybe even value.SomeNotNull() etc. Usually I simply use the extension methods, e.g. In my opinion, the only situation in which an implicit conversion "looks nicer", is when converting the return value (e.g. Nevertheless, I will give it some thoughts. You are welcome to come up with more pros/cons. /Nils |
Ok. This is all reasonable and those extension methods for conversion really help a lot. Since there are many possible interpretations for this implicit behavior (some might prefer null conversion to None, others might expect Some(null)), then it's hard to make a preference. And when one choice is made it might introduce some unexpected behaviors for end users. Considering that, I agree, that explicit conversion is much safer way to go and this question is resolved for me. |
Waiting for .NET Core compatible NuGet packages to be released 😄 |
@janno-p Just FYI, .NET Core support has just been released. Enjoy :) |
Great! I will. |
Would it be very awful if Option type had implicit operator for converting value from
T => Option<T>
?It would allow to use shortcut for assigning option values. Instead of
Option<bool> opt = Option.Some(true);
I could useOption<bool> opt = true;
The text was updated successfully, but these errors were encountered: