Some questions about writing custom functions. #458
-
Hello. I came across some questions when I wrote custom functions. I found that the custom function cannot use some keys like The error example:
The error is :
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello! I'm afraid you've got a few things slightly mixed up. You cannot define rules in functions (or in other rules), and that's what test(params) := result{
default defenseResult := "reject"
defenseResult := "pass" if {
count(params) <= 0
}
result := {
"result": defenseResult
}
} looks like. You can, however, achieve the desired behaviour differently: package example.test
import future.keywords.if
test(params) := wrap("pass") if count(params) == 0 # negative should be impossible
test(params) := wrap("reject") if count(params) > 0
wrap(res) := {"result": res} |
Beta Was this translation helpful? Give feedback.
Hello! I'm afraid you've got a few things slightly mixed up. You cannot define rules in functions (or in other rules), and that's what
looks like.
You can, however, achieve the desired behaviour differently: