Skip to content
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

collection expressions for Option<T> #760

Open
FreeApophis opened this issue Nov 15, 2023 · 0 comments
Open

collection expressions for Option<T> #760

FreeApophis opened this issue Nov 15, 2023 · 0 comments
Labels
to discuss There are open points which need to be discussed

Comments

@FreeApophis
Copy link
Member

FreeApophis commented Nov 15, 2023

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];
  • Do we really want that?

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

@FreeApophis FreeApophis added the to discuss There are open points which need to be discussed label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to discuss There are open points which need to be discussed
Projects
None yet
Development

No branches or pull requests

1 participant