3 ms·
Similar to the new null-conditional operator in C#? https://msdn.microsoft.com/en-us/library/dn986595.aspx https://msdn.microsoft.com/en-us/library/dn986595.as
by nikon 11y ago
Similar to the new null-conditional operator in C#?
https://msdn.microsoft.com/en-us/library/dn986595.aspx https://msdn.microsoft.com/en-us/library/dn986595.aspx
- richmarr 11y agoGroovy's predates this one, but yeah, looks similar.
- vorg 11y agoI remember Groovy didn't allow ? on indexes like in the third C# example: int? count = customers?[0]?.Orders?.Count(); I remember asking for it but it never came. I don't think Ruby's proposed .? syntax would work with indexes either unless they use [? ]. Neither Java nor Groovy has the int? declaration shown which enforces the optionality. The C# version looks more versatile. Back when Groovy was more popular, its backers also discussed a cascading ? on their mailing list but it never happened. If C# had cascading ? then the example above would be int? count = customers?[0].Orders.Count(); because the first ? would ripple to the subsequent member accesses and index lookups.
- richmarr 11y agoYep. I remember waving my arms and crying for ES6 to have '?.' back when the spec was open, but there was a lexical issue. It's frustrating to have such useful features blocked by such seemingly small problems as ambiguous patterns of characters.
- moonshinefe 11y agoIndeed it seems similar. I can't recall if the C# one allows chaining however.
- biot 11y agoThe third C# example shows: int? count = customers?[0]?.Orders?.Count(); So yes, it can definitely be chained as the following paragraph in the linked page explains.