Re:Apple is patenting Swift features
by dotuser on Friday January 25, 2019 @12:00PM
(#18999857)
one thing though, in swift you can actually mutate fields using optional chaining, e.g. person?.name = "Bob". you can't do that in c#. not sure about rust but in scala you would unwrap the optional with a foreach or something.
[ Parent
| on HN ]
In Groovy you can mutate through optional (null-safe) chaining, eg:
x = [ foo: [ bar: 1] ]
x.foo.bar // 1
x.boo?.bar // null because x.boo is null
x.boo?.bar = 1 // succeeds even though x.boo is null
x.boo // still nullI knew I had seen this somewhere else. I don't understand why C# doesn't support this since most C# code is mutable anyway. I can see why it doesn't fit well with functional languages but C# usually espouses pragmatism over purity and having this would clean up a lot boilerplate null checking.