Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement safe navigation/null-coalescing operator #229

Open
masak opened this issue May 23, 2017 · 2 comments
Open

Implement safe navigation/null-coalescing operator #229

masak opened this issue May 23, 2017 · 2 comments

Comments

@masak
Copy link
Owner

masak commented May 23, 2017

Code like this:

my bossName;
if employee != None {
    if employee.boss != None {
        bossName = employee.boss.name;
    }
    else {
        bossName = None;
    }
}
else {
    bossName = None;
}

Could profitably be rewritten by using a ?. safe navigation operator:

my bossName = employee?.boss?.name;
@masak masak changed the title Implement Elvis operator Implement safe navigation operator May 26, 2017
@masak masak changed the title Implement safe navigation operator Implement (Elvis) safe navigation operator Jul 2, 2018
@masak masak changed the title Implement (Elvis) safe navigation operator Implement safe navigation operator Feb 22, 2019
@masak
Copy link
Owner Author

masak commented Feb 22, 2019

I decided not to refer to this as "the Elvis operator", since Wikipedia seems to be of the opinion that that's the name of another operator, usually spelled ?: but with the same semantics as 007 (and Perl 6) infix:<||>.

@masak masak changed the title Implement safe navigation operator Implement safe navigation/null-coalescing operator May 16, 2019
@masak
Copy link
Owner Author

masak commented Jul 29, 2019

The TC39 proposal makes a good point I hadn't considered: the operator is short-cricuiting such that any side effects happening on the rhs of a ?. with a none lhs won't run. We want to do it that way too, I'm sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant