Skip to content

Dealing with properties where null is valid #1120

Answered by sparerd
speterson-zoll asked this question in Q&A
Discussion options

You must be logged in to vote

I think you have it almost right with your last example. The Value is null exception you are getting is because LanguageExt forbids nulls unless explicitly allowed (using the ____Unsafe functions). In this case, the Validation type does not have any overloads for accepting nulls.

Rather than propagating the nullable type, consider going all-in on using the alternate value monads. Changing the return type from Validation<Error, DateTime?> to Validation<Error, Option<DateTime>> provides the same information but with better safety. Now instead of a Success case with a null value, we give it None.

public static Validation<Error, Option<DateTime>> ParseNullableDateTime(Option<string> value) =>

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by speterson-zoll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants