-
-
Notifications
You must be signed in to change notification settings - Fork 463
-
Hey, good day am trying to integrate this into a project as a middleware for the project, I predicted the script is gonna get a little complex, is there a way to have if statements or if-else, I can’t find any documentation or issues about this.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
Now Expr has control flows!
let foo = if bar > 0 { true } else { false }
Replies: 10 comments 11 replies
-
As far as I know, Expr only has the ternary statement:
valueA != valueB ? do-if-true : do-if-false
It's in the Operators.
Beta Was this translation helpful? Give feedback.
All reactions
-
Yeap. But I do want to implement if statements as well.
Beta Was this translation helpful? Give feedback.
All reactions
-
If it could support control flow and custom functions, that would be great.
Beta Was this translation helpful? Give feedback.
All reactions
-
Custom functions already supported.
Beta Was this translation helpful? Give feedback.
All reactions
-
maybe we can implement a simple "pattern matching" first?
match a {
1 -> "foo"
2 -> "bar"
default -> "none"
}
or
switch {
case <condition 1> -> "foo"
case <condition 2> -> "bar"
default -> "none"
}
something like aboves is really help
Beta Was this translation helpful? Give feedback.
All reactions
-
BTW: currently I use go template + sprig for implement my business logic, it's too heavy and a bit slow than expr. The blocker of my expr migration is if statement or pattern matching.
Beta Was this translation helpful? Give feedback.
All reactions
-
So what king of the problem are you trying to solve? Please, more context.
Beta Was this translation helpful? Give feedback.
All reactions
-
Here an example of my side project, https://github.com/phuslu/liner/blob/master/example.yaml#L47-L66 , please the "policy" and "dialer" field.
Beta Was this translation helpful? Give feedback.
All reactions
-
k8s helm also use same idiom, see https://helm.sh/docs/chart_template_guide/control_structures/
Beta Was this translation helpful? Give feedback.
All reactions
-
Would greatly benefit control flow as well. Either switch case or if/else are good options for my use-cases. I can work around with ternary however, just less practical.
Beta Was this translation helpful? Give feedback.
All reactions
-
@antonmedv Any plans on having if-else in near future? It's easier for business folks as well to use
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, we are planning to implement if-else in near future. I guess this will be a new feature after current release.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
I'm facing a scenario where if-else proves very helpful, consider this script:
if input1 != "" { return input1 } b := calculateB(input2); c := calculateC(); return getResult(b, c);
To do this in go expr, I'm currently planning to write this:
let b = input1 == "" ? calculateB(input2) : nil; let c = input1 == "" ? calculateC() : nil; input1 != "" ? input1 : getResult(b, c)
It would be so much nicer if the expression language has a "return" keyword, or a rust-like if-else expression:
if input1 != "" { input1 } else { let b = calculateB(input2); let c = calculateC(); getResult(b, c) }
I would say this is easier to read.
Beta Was this translation helpful? Give feedback.
All reactions
-
True! This is why we are working on it. ping @OlgaNovg ;)
Beta Was this translation helpful? Give feedback.
All reactions
-
#736
Looks like this pull request has been open few months ago. Is there a path forward?
(I'm evaluating expr for a use case which needs control flow)
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes! @OlgaNovg is also waiting long time already)
Beta Was this translation helpful? Give feedback.
All reactions
-
Hey folks - excited that this is now merged! Is there a timeline for the next release?
Beta Was this translation helpful? Give feedback.
All reactions
-
Soon! I have to fix a few issues before. And i want to add support for sequence of expressions.
Beta Was this translation helpful? Give feedback.
All reactions
-
Now Expr has control flows!
let foo = if bar > 0 { true } else { false }
Beta Was this translation helpful? Give feedback.
All reactions
-
where is the documented?
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
you can read this in 1.17.0 release note.
Very small and short, but there is a document too. (Maybe no one made a detailed document PR yet)
스크린샷 2025年08月19日 오전 11 55 49
Beta Was this translation helpful? Give feedback.