Skip to content

Create list from array for Evaluation #157

Discussion options

You must be logged in to vote

If you want to aggregate an array of the resource names, you could either use an array comprehension, like:

import future.keywords.in

obj := {"data": [
	{
		"name": "resource",
		"resource": {"data": {"name": "good-eval-name"}},
	},
	{
		"name": "resource",
		"resource": {"data": {"name": "bad-eval-name"}},
	},
]}

resource_names := [name | some item in obj.data; name := item.resource.data.name]

Or you could use a partial rule to build a set of them:

resource_names[name] {
    some item in obj.data
    name := item.resource.data.name
}

(You could also use a set comprehension to achieve the same outcome, they are functionally equivalent)

Then simply use in to check for membership:

not "ba…

Replies: 1 comment 1 reply

Comment options

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

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