Discussion: Withers and collections #3262
Replies: 9 comments
-
An alternate syntax, which may prevent syntactic ambiguity, could be record with { Owner with { Name = "name" } } |
Beta Was this translation helpful? Give feedback.
-
I don't think there is any? I'm specifically thinking |
Beta Was this translation helpful? Give feedback.
-
Maybe there isn't one, just recording some options in case. |
Beta Was this translation helpful? Give feedback.
-
See also #77 |
Beta Was this translation helpful? Give feedback.
-
@orthoxerox forgot to mention that issue. This is supposed to be a tiny increment to that proposal. Updated. |
Beta Was this translation helpful? Give feedback.
-
As |
Beta Was this translation helpful? Give feedback.
-
I don't like that the syntax Collection initializers can get away with that, because they're usually adding items to an empty collection (or at least some kind of "default" collection), but that's not the case here. |
Beta Was this translation helpful? Give feedback.
-
If that's confusing, I don't think I think if you want to be completely clear, there should be a way to specify the exact operation, currently, the one time you need to node with { ArgList = { Args = node.ArgList.Args.Remove(itemOrIndex) } } Maybe |
Beta Was this translation helpful? Give feedback.
-
I can accept the "add" behavior because wither does creation, so is collection initializer. I agree the |
Beta Was this translation helpful? Give feedback.
-
As a pre-requirement, we need to relax with-expression syntax to accept nested initializers:
This is using the exact same grammar as object/collection initializers.
For an extended form of the syntax, see #77.
Then we can accept a collection initializer with the following generated code:
Such code is already accepted by object/collection initializer syntax so we can use the same parsing rules.
Currently the collection initializer doesn't care about the return type on
Add
method. In withers, we require theAdd
method to return a new object to be passed to With method.To avoid a new allocation on every addition, we could say if there is an
AddRange
method, we'll use that instead,Note: if we wanted a replacement, we can write
That's exactly how collection initializers work today.
Beta Was this translation helpful? Give feedback.
All reactions