Hacker News new | ask | show | jobs
by zmmmmm 2700 days ago
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 null
1 comments

I 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.