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

Provide examples of the conditional operator #641

Open
benjaminapetersen opened this issue Feb 2, 2023 · 1 comment
Open

Provide examples of the conditional operator #641

benjaminapetersen opened this issue Feb 2, 2023 · 1 comment
Labels
question Further information is requested

Comments

@benjaminapetersen
Copy link

Change
It took several passes over the documentation and some experimentation to realize that a basic "if" statement is indeed easy to write in CEL simply using logical operators. Given that CEL is a golang project and has roots in the kubernetes community as well, clarifying that the lack of an "if" statement does not mean it is unable to perform this type of logic would be ideal.

Example

CEL does not have an "if" statement, however, similar decision making flows are trivial to perform using its built-in logical operators. For example:

expr:  'firstName != "bob" ? firstName + ":" + lastName : firstName'

Understanding that CEL can perform simple conditional logic and return one value or another was not immediately obvious.

Alternatives considered
Briefly list alternative designs, or an example of the functionality to be replaced.

@TristonianJones
Copy link
Collaborator

@benjaminapetersen I think this is a good example to include in the github.com/google/cel-spec

The ternary operator isn't quite an if statement since a classic if statement doesn't guarantee a return value; however, you can mimic if-else and if-elseif-... flows this way.

@TristonianJones TristonianJones changed the title Improve documentation/examples to make it more obvious that logical operators replace constructs like "if" statements Provide examples of the conditional operator Mar 9, 2023
@TristonianJones TristonianJones added the question Further information is requested label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants