Skip to content

Overwrite the value of variable | x = x+1 | x= sum(x+1) #192

Answered by srenatus
Vighi88 asked this question in OPA and Rego
Discussion options

You must be logged in to vote

As @anderseknert pointed out in open-policy-agent/opa#4679 (comment), an object isn't ordered. However, for completeness sake, here's one way to check the ordering of something that is ordered, an array:

package play
import future.keywords

ordering := ["apple", "banana", "capybara"] # the desired ordering

is_ordered(x) {
    every idx, element in ordering {
    	x[idx].name == element
    }
    count(ordering) == count(x)
} else = false

test_correct = is_ordered([{"name": "apple"}, {"name": "banana"}, {"name": "capybara"}])

test_incorrect = is_ordered([{"name": "banana"}, {"name": "apple"}, {"name": "capybara"}])

test_short = is_ordered([{"name": "apple"}, {"name": "banana"}])

👉 play…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by Vighi88
Comment options

You must be logged in to vote
2 replies
@srenatus
Comment options

@Vighi88
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
Converted from issue

This discussion was converted from issue #191 on May 13, 2022 08:28.