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

Proposal: list-patterns on enumerables #6574

Open
jcouv opened this issue Oct 19, 2022 · 3 comments
Open

Proposal: list-patterns on enumerables #6574

jcouv opened this issue Oct 19, 2022 · 3 comments
Assignees
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Oct 19, 2022

Allow is [ 1, 2, 3 ] (list pattern) and is [ 1, ..var x, 5 ] (slice pattern) on enumerables.

Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/list-patterns-enumerables.md

Background:

Design meetings:

@jcouv jcouv self-assigned this Oct 19, 2022
@Xyncgas
Copy link

Xyncgas commented Jun 12, 2023

why not [1; x] [1; x; 5]
since it's a new language proposal, we can throw away that var, similar to how we can write lambda without type name on its parameter, it just matches
maybe we can even do var myLambda = [1; x] => true | unmatched => false; myLambda(myList);

@KennethHoff
Copy link

It's not a new language feature. It already exists for indexable collections, like arrays and lists.

@En3Tho
Copy link

En3Tho commented Jul 22, 2023

[1; x] feels like a (personally) long awaited pattern matching on non const values rather that x being a declared variable here. Also, as stated above it's already a feature on indexable types. It's just that it's harder to do properly with sequences because it most likely will result in implicit buffering in complex cases like [1, ..var x, 5] which might be not desirable. At least with indexable collections this behavior is explicit and based on public members of those collections.

@333fred 333fred added this to the Working Set milestone Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants