4 ms·
C# does this already https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/with-expression https://learn.microsoft.com/en-us/dotnet/cshar
by inglor 3y ago
C# does this already https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/with-expression https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... - works pretty well. It's good that Java is finally getting more ergonomic these past few years.
- nonsensikal 3y agoI thought of F# record expressions immediately https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/copy-and-update-record-expressions https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
- zokier 3y agoThe C# with seems bit more restricted though because it uses object initializer syntax while Java has full-blown code block, so in Java you can put arbitrary statements in. Also in Java you get the original values in the with statement, which I don't see in C#.
- marwis 3y agoAlso C# records do not support initialization code so you can't validate arguments :(