7 ms·
I didn't imply it was desired or wasn't possible...? Another reply to my comment clarified that Optional also only applies to value types, which makes it analog
by jpfed 10y ago
I didn't imply it was desired or wasn't possible...? Another reply to my comment clarified that Optional also only applies to value types, which makes it analogous to Nullable. There's no reason to port it (as opposed to any other implementation of an Optional type) over.
What is really necessary is an equivalent for reference types.
struct Maybe<T> where T : class {
private bool _isInitialized;
private T _data;
public Maybe(T data) {
_isInitialized = (data != null);
_data = data;
}
// ...etc
}