Replies: 7 comments 14 replies
-
My immediate reaction is same as 3.iii
For matching property and collection together, one idea is |
Beta Was this translation helpful? Give feedback.
-
Is it worth considering the [| 1, 2, 3 |] pattern that F# uses for arrays?
…On Tue, 15 Dec 2020 at 08:12, Erik Hermansson ***@***.***> wrote:
I would like to be able to use patterns for dictionary keys as well: [] {
[var key]: "some value" } or [] { [var userId]: { Parent: { Id: 42 } } }.
I'm not sure the length brackets are useful for dictionaries, but maybe
they are.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4232 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADIEDQJ7AZV53VRWVTSD3EDSU4K7TANCNFSM4U3P4O2A>
.
|
Beta Was this translation helpful? Give feedback.
-
tangential: Why is the decomposition of a class written as On the meeting notes themselves:
|
Beta Was this translation helpful? Give feedback.
-
I'm strongly against enabling length checks against
This isn't quite true. Arrays implement ICollection a = new[] { 1, 2, 3 };
Console.WriteLine(a.Count); |
Beta Was this translation helpful? Give feedback.
-
I like this. We already have good syntax for testing e.g. The user can also implement their own types implementing e.g. So, how about a strawman, using a new keyword to match on the items returned by an object's enumerator ( o is int[] { Count: 3 }
// .GetEnumerator() returns an enumerator which yields exactly these 3 items, or optimized equivalent
o is int[] { items { 1, 2, 3 } }
// Redundant? But possible!
o is int[] { Count: 3, items { 1, 2, 3 } }
// .GetEnumerator().MoveNext() return false, or optimized equivalent
o is int[] { items { } } Then this could work with the proposed // Indexer yields these values when given these keys
o is int[] { [0]: 1, [1]: 2 } Of course, extended to objects which have indexers which take multiple parameters: o is SomeObject { [1, 2]: 3 } These apply to all types which have an indexer / enumerator: // Again, matches using the indexer
o is Dictionary<string, string> { ["a"]: "b" }
// Matches the `KeyValuePairs` returned from its enumerator (in order)
o is SortedDictionary<string, string> { items { KeyValuePair<string, string>("a", "b"), KeyValuePair<string, string>("c", "d") } }
// Equivalently
o is SortedDictionary<string, string> { items { ("a", "b"), ("c", "d") } }
Developers need to know this anyway: that ship sailed when |
Beta Was this translation helpful? Give feedback.
-
I wanted to write this piece of code the other day: if (Regex.Match(input, "prefix_(?<num>\\d+)") is { Success: true, Groups: { ["num"]: { Success: true, Value: string n } } } && int.TryParse(n, out int num))
{
// use num
} Obviously didn't work like that, and while I'm not totally sure about the syntax, I was wondering if this was included here as part of "list" patterns (since What I wrote instead (because it works today) is this: if (Regex.Match(input, "prefix_(?<num>\\d+)") is { Success: true } match && match.Groups["num"].Success && int.TryParse(match.Groups["num"].Value, out int num))
{
// use num
} Also, while I was typing this, I noticed that the former is pretty verbose and often longer than the classic alternative once you use a variable name longer than 3 characters (such as |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I like the syntax of the |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/master/meetings/2020/LDM-2020-12-14.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions