-
Notifications
You must be signed in to change notification settings - Fork 15
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
Remove Maybe type and change Option to be a readonly struct #57
Comments
Have abandoned this idea as read only structs are just weird. |
Do you have any insight on the weirdness you found? |
Well yes, I do. And having gone full circle, I'm re-opening this. The reason I claimed that readonly structs are weird is due to the distinction between "read only" and "immutable". In C#, class C
{
readonly List<int> _x = new List<int>();
void ReadonlyNotImmutable() => _x.Add(1);
} The "value" of Readonly structs apply this same rule, but it creates odd results. So for example, the following code: class FakeTuple
{
public int a;
public int b;
}
readonly struct S
{
readonly (int a, int b) _x;
readonly FakeTuple _y;
public S(int n)
{
_x = (n, n);
_y = new FakeTuple { a = n, b = n };
}
int X { set { _x.a = value; } }
int Y { set { _y.a = value; }}
} gives an error on But what I was missing is the simple idea that, just like with a readonly field, a readonly struct guarantees its value cannot change. And the value of a struct is the value of its fields. So the tuple, being a struct itself, cannot change the value of its fields as that would change its own value and thus the value of the struct, So having had that lightbulb moment, I've gone back and re-introduced that readonly struct for |
Adding a checklist here for all the types that can become readonly structs:
|
… classes in SuccincT are now either sealed or static.
Closing as implemented. |
This is a major breaking change:
Maybe<T>
will need to change to useOption<T>
.Option<T>
handlesnull
changes:i.
Option<string>.Some(null)
will throw anArgumentNullException
.ii. As the type supports implicit casting of
T
toOption<T>
, castingnull
in this way will result in aNone
:The text was updated successfully, but these errors were encountered: