-
Notifications
You must be signed in to change notification settings - Fork 220
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
added default (elvis) operator #638
base: master
Are you sure you want to change the base?
Conversation
Ah. I meant to open this in draft mode, and I can't seem to change it now. |
@@ -40,6 +40,7 @@ const parser = (() => { | |||
'<=': 40, | |||
'>=': 40, | |||
'~>': 40, | |||
'?:': 40, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any input on what the binding power should be on this operator?
Hi Mark, many thanks for taking the lead on this, I’m happy that we get this into the language. Re-reading the discussion, I think there are two separate operations that we could add:
As far as implementation is concerned, it would probably be easiest to modify the parser to check whether the next token is On the question of roadmap, I don’t have any committed plans at the moment, but I’m having thoughts in the following areas:
Neither of these would affect your proposal though. |
I agree. The A?:B is nice in that it simplifies many expressions written as A ? A : B but it might slightly miss the actual use case of "we want to provide a default value when there is none". However, we can start with this operator and see where we end up. |
Implements request from #370.
I have never been sure about how the project owners feel about the addition of operators. Functions are one thing, but an operator is a first-class citizen, and eating one up has roadmap-altering consequences. Is there even a roadmap?
Of all the proposed syntaxes, I opted to use the elvis operator
?:
since it's so close to its functional equivalent.property ? property : 'default'
becomesproperty ?: 'default'
. (Just collapse the?
and the:
of a ternary.)Draft mode for now since:
Thanks for looking!