Skip to content
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

Extension method to convert an Option<T> to a Nullable<T> #18

Closed
wants to merge 1 commit into from

Conversation

atifaziz
Copy link
Contributor

This PR helps with #13 when a conversion to Nullable<T> is needed.

It also helps with the example presented in issue #17, which can be written as:

var d = Option.Some(new DateTime(2010, 12, 31));
var s = string.Format(new CultureInfo("de-DE"), "{0:D}", d.ToNullable());
Console.WriteLine(s);

instead of:

var d = Option.Some(new DateTime(2010, 12, 31));
var s = string.Format(new CultureInfo("de-DE"), "{0:D}", d.Match(v => v, () => default(DateTime?)));
Console.WriteLine(s);

That is, of course, while #17 is open.

The method being added by this PR is called ToNullable() instead of ValueOrNull() because you cannot overload on generic type parameter constraints and if ValueOrNull() is subsequently added then that would only apply to Option<T> where T is a reference.

@nlkl nlkl added this to the Optional 4.0.0 milestone Aug 14, 2017
@nlkl nlkl self-requested a review August 14, 2017 06:43
@nlkl nlkl self-assigned this Aug 14, 2017
nlkl added a commit that referenced this pull request Aug 17, 2017
@nlkl
Copy link
Owner

nlkl commented Aug 17, 2017

Closing issue, as this has now been implemented.

@nlkl nlkl closed this Aug 17, 2017
@atifaziz atifaziz deleted the ToNullable branch October 10, 2017 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants