Replies: 3 comments
-
HI @tpihl The helper approach is the intended approach by design for users to define their own function. Solution 1 : You can simply fork this repo and add your custom function in ast/BuiltInFunctions.go. Instead of using Its quite common to do this way, as you may observe many people fork this project to do it this way. You can create a PR if you think the function is generic enough for other user to use. I think this is the simplest, fastest alternative. Solution 2 : To add // create an anonymous function
myfunc = func (param string) {
...
}
// add the function into data context
dataCtx.add("MyFunc", myFunc) and from the rule you can use
I have few downside in this approach, you have to add the function everytime you create |
Beta Was this translation helpful? Give feedback.
-
Hi newwm4n, That makes sense. Running with my own fork isn't really my thing, i think this is good software and that should be visible. The solution to add the function in every call is the same no matter if it's a helper or not, so not really a downside, is it? Would if be possible to add the function when you create the knowledge-library? If not, i'd be happy happy with adding the function to every fact, no problem. I already have a wrapper handlingen the different facts for some other reasons. |
Beta Was this translation helpful? Give feedback.
-
No, i'm afraid not. |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
I really like the functions we can put in rules. But based on the actual rule engine implementatiton it may make sense to be able to add more functions not related to a fact (since there is no fact data, only functions).
I'm currently using facts like "helper" or "action" or similar, but it really remove some of the readability/flow in the rule. One example from one of my "then" sections where "helper" only raise questions when the rule is read by humans:
fact1.Data1 = helper.CalculateSomethingMakeingSenseInThisRuleengine(fact1.Data2)
or in a "with" statement
helper.EstimatedValueOf(fact1) > 7
Describe the solution you'd like
fact1.Data1 = CalculateSomethingMakeingSenseInThisRuleengine(fact1.Data2)
EstimatedValueOf(fact1) > 7
Describe alternatives you've considered
Not really, only a question on possible improved readability and simplification of rules (by adding some magic)
Additional context
Same context as my other question #172
Beta Was this translation helpful? Give feedback.
All reactions