Adding the ?. null verification
Lionello Lunesu via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 18 08:59:25 PDT 2014
On 18/06/14 23:42, Etienne wrote:
> I find myself often repeating this boilerplate:
>
> if (obj.member !is null)
> {
> if (obj.member.nested !is null)
> {
> if (obj.member.nested.val !is null)
> {
> writeln(obj.member.nested.val);
> }
> }
> }
>
> I have to admit it's a little frustrating when you see swift's ?. syntax
> notation, it would be a little more practical to be able to write
>
> writeln(obj.member?.nested?.val);
>
>
> Based on http://appventure.me/2014/06/13/swift-optionals-made-simple/
>
>
> Any thoughts?
I want non-null in the type system! To put a nullable reference into a
non-null variable you need to check first, but from then on the compiler
can ensure it's never null!
More information about the Digitalmars-d
mailing list