Replies: 9 comments
-
Why not take it to the next level?
where |
Beta Was this translation helpful? Give feedback.
-
Separated discards are better for readability |
Beta Was this translation helpful? Give feedback.
-
This is not equivalent to a number of discards, as it's indifferent to the "length" of a list (or tuple). |
Beta Was this translation helpful? Give feedback.
-
I think if (tuple is (_ : int i)) //Ends with any integer
if(tuple is (1 : _)) //Starts with 1
if(tuple is (0 : _ : 0)) //Starts and ends with 0
if(tuple is (0 , 1 : _ )) //Starts with 0 then 1 Same goes for lists with |
Beta Was this translation helpful? Give feedback.
-
I thought about that as a "repeat pattern", e.g. |
Beta Was this translation helpful? Give feedback.
-
#221 has been closed. The pattern part can be reused here for tuples and lists. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
It's a declarative way to match a few elements of an array not the whole thing. Note that "array patterns" must match the whole array so, |
Beta Was this translation helpful? Give feedback.
-
Moved from dotnet/roslyn#5811
A sequence discard would allow you to skip a sequence of values (zero or more) in a list pattern. For example, the following would match any array that ends with 1.
There is no need to have a "one or more" variation since you can use a regular discard to simulate that,
To keep the matching logic simple, we permit the sequence discard only once in a list pattern.
Open issue: would it be useful to allow this also for tuples?
The compiler uses
ITuple
interface if the tuple type is not known at compile-time.Beta Was this translation helpful? Give feedback.
All reactions