Skip to content

Some questions about writing custom functions. #458

Discussion options

You must be logged in to vote

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}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JinXiu2023
Comment options

Answer selected by JinXiu2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants