String.Empty returns Some #1186
-
Hi, I'm wondering, since I cant find it on the webs if this is intended or not. If I have a piece of code where I set a String.Empty for example. If in my example the moon isn't blue it should return String.Empty.
The reason I find this as unintended is that in your own docs you state NULL is the worst thing ever made in computer science. I can't find the recommended way of handling this. (I know in the code I made above I could be if == true return GetMoonInfo(); But there are use cases where during logic it is possible to set a string as empty.) Or you start with an empty string and do some logic that might not give value to the string with certain conditions. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you want to filter for empty strings, you can do something like this:
|
Beta Was this translation helpful? Give feedback.
null
andstring.Empty
are two distinctly different values.Optional((string)null)
will returnNone
, whileOptional(string.Empty)
will returnSome(string.Empty)
.This is completely intentional since you might want to handle both cases separately.
If you want to filter for empty strings, you can do something like this: