Closed DavidArno closed 6 years ago
What will value
contain if hasValue
is false
?
default(T)
would seem the obvious choice. I'd prefer the idea that its undefined, but out
parameters have to be set, always, so that isn't an option.
If you think this inherently a bad idea though, I'm open to being convinced to drop it.
I don't think that's a bad idea, but I feel like it should be consistent with how Option<T>.Value
behaves. Right now it's determined to throw an exception if HasValue == false
, so maybe Option<T>.Value
should return default(T)
as well in this case.
If I changed Option<T>.Value
to return default<T>
when there's no value, then that would be a breaking change. So the choices are:
Option<T>.ValueOrDefault
property that behaves this way and leave Option<T>.Value
, as is.Option<T>.ValueOrDefault
seems legit.
Added to v3.1
Based on a suggestion from @pkanavos:
Option<T>
(andMaybe<T>
if it doesn't just work through implicit casting):Success<T>
,Either<T1, T2>
and union types.