-
Notifications
You must be signed in to change notification settings - Fork 65
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Add the Ternary Operator #10
Comments
omg yes |
The actual problem with ternary operator is that people can't agree on how to format it. Of course every serious person knows the one true way though: c1 ? v1 :
c2 ? v2 :
c3 ? c31 ? v31 :
v3d :
vd; |
There is already |
This will be in our "easy to use new super awesome gateway language" to introduce users from C#, Java, JavaScript, Python, etc. to the way of the crab: I don't have any responses on this one yet and it makes me sad :(. Lol. I actually believe in this one tho. I think it's the key ingredient to taking over the world. Although we need a new name for it now. Crabby has been taken for clippy. |
Can we elaborate more on its integrarion with Let's we have
|
What if this was done with a macro? let some_var = ?!(some_condition ? "true" : "false"); |
And it would literally just expand to this |
Brilliant. Just brilliant. Yes. |
I know this is a pipe-dream which is why I didn't take my little "RFC" message seriously. I do think that I suggest we change it from let b = true;
let i = (b ?? "Yes") ?: "No"; In this snippet, // Impl for the `??` operator
impl<T> core::ops::IsTrue for bool {
type Output = T;
fn is_true(self, rhs: T) -> Option<Self::Output> {
if self {
Some(rhs)
} else {
None
}
}
} For With both operators implemented, the equivalent "desugared" code from the first snippet would look like this: let b = true;
let i = (if b {
Some("Yes")
} else {
None
}).unwrap_or("No"); There definitely could be a better way at implementing this, but using |
If using the value if True else value2 yeah it is kinda the opposite of but still better than |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Summary
Now that there's a fork getting enough traction, I'd like to propose our best competitive advantage: The Ternary Operator. It'll make my code look nice and run faster I think
Motivation
Please. Listen to me, okay. It's all I've wanted since like 2015. It can't be that hard, I've made my own language before and it had a ternary operator. Just figure it out idk
Guide-level explanation
Reference-level explanation
It would look like this
Drawbacks
None
Rationale and Alternatives
Rationale:
Alternatives:
Unresolved Questions
Future possibilities
The text was updated successfully, but these errors were encountered: