Open jcouv opened 2 years ago
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);
It's not a new language feature. It already exists for indexable collections, like arrays and lists.
[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.
Allow
is [ 1, 2, 3 ]
(list pattern) andis [ 1, ..var x, 5 ]
(slice pattern) on enumerables.Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/list-patterns-enumerables.md
Background:
Design meetings: