You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since we have the pattern match for Option [var value] with C#12 the question is: should an Option<T> be constructible with a collection expression too?
Option<T>.None would become []
Option.Some(value) would become [value]
Open questions.
this could be an opportunity to remove the implicit operator. (breaking change)
What would we do if there is more than one value Option<int> number = [42, 1337];
We have ignored the problems for the pattern, because you can write such a pattern, but it will never be matched.
This could be abused as a abbrevation for SingleOrNone() or FirstOrNone() depending on the decided behaviour in combination with the spread operator. Option<int> number = [..collection];
Since we have the pattern match for Option
[var value]
with C#12 the question is: should anOption<T>
be constructible with a collection expression too?Option<T>.None
would become[]
Option.Some(value)
would become[value]
Open questions.
Option<int> number = [42, 1337];
SingleOrNone()
orFirstOrNone()
depending on the decided behaviour in combination with the spread operator.Option<int> number = [..collection];
What would we need to do?
Implement the Collection Builder as described here:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions
The text was updated successfully, but these errors were encountered: