title: OPA/Rego execute function for each element of an array
body: <p>I am new at OPA/Rego and I am trying to write a policy to check if an Azure Network Security Group contains all the rules that I define on an array</p>
  <pre><code>package sample
  default compliant = false
  toSet(arr) = {x | x := arr[_]}
  checkProperty(rule, index, propertySingular, propertyPlural) = true
  {
      object.get(input.properties.securityRules[index].properties, propertySingular, &quot;&quot;) == object.get(rule, propertySingular, &quot;&quot;)
      count(toSet(object.get(input.properties.securityRules[index].properties, propertyPlural, [])) - toSet(object.get(rule, propertyPlural, []))) == 0
  }
  existRule(rule) = true
  {
      input.properties.securityRules[i].name == rule.name
      input.properties.securityRules[i].properties.provisioningState == rule.provisioningState
      input.properties.securityRules[i].properties.description == rule.description
      input.properties.securityRules[i].properties.protocol == rule.protocol
      checkProperty(rule, i, &quot;sourcePortRange&quot;, &quot;sourcePortRanges&quot;)
      checkProperty(rule, i, &quot;destinationPortRange&quot;, &quot;destinationPortRanges&quot;)
      checkProperty(rule, i, &quot;sourceAddressPrefix&quot;, &quot;sourceAddressPrefixes&quot;)
      checkProperty(rule, i, &quot;destinationAddressPrefix&quot;, &quot;destinationAddressPrefixes&quot;)
      input.properties.securityRules[i].properties.access == rule.access
      input.properties.securityRules[i].properties.priority == rule.priority
      input.properties.securityRules[i].properties.direction == rule.direction
  }
  compliant
  {
      rules := [
              {
                  &quot;name&quot;: &quot;name1&quot;,
                  &quot;provisioningState&quot;: &quot;Succeeded&quot;,
                  &quot;description&quot;: &quot;description1&quot;,
                  &quot;protocol&quot;: &quot;*&quot;,
                  &quot;sourcePortRange&quot;: &quot;*&quot;,
                  &quot;destinationPortRange&quot;: &quot;53&quot;,
                  &quot;destinationAddressPrefix&quot;: &quot;*&quot;,
                  &quot;access&quot;: &quot;Allow&quot;,
                  &quot;priority&quot;: 1,
                  &quot;direction&quot;: &quot;Inbound&quot;,
                  &quot;sourceAddressPrefixes&quot;:
                  [
                      &quot;xx.xx.xx.xx&quot;,
                      &quot;xx.xx.xx.xx&quot;,
                      &quot;xx.xx.xx.xx&quot;
                  ],
              },
              {
                  &quot;name&quot;: &quot;name2&quot;,
                  &quot;provisioningState&quot;: &quot;Succeeded&quot;,
                  &quot;description&quot;: &quot;description2&quot;,
                  &quot;protocol&quot;: &quot;*&quot;,
                  &quot;sourcePortRange&quot;: &quot;*&quot;,
                  &quot;destinationPortRange&quot;: &quot;54&quot;,
                  &quot;sourceAddressPrefix&quot;: &quot;*&quot;,
                  &quot;access&quot;: &quot;Allow&quot;,
                  &quot;priority&quot;: 2,
                  &quot;direction&quot;: &quot;Outbound&quot;,
                  &quot;destinationAddressPrefixes&quot;:
                  [
                      &quot;xx.xx.xx.xx&quot;,
                      &quot;xx.xx.xx.xx&quot;,
                      &quot;xx.xx.xx.xx&quot;
                  ]
              }
          ]
      #checks
      existRule(rules[i])
  }
  </code></pre>
  <p>The issue seem to be that when execute <code>existRule(rules[i])</code> if one of the rules match it returns true, don't mather if other rules doesn't
  If I replace <code>existRule(rules[i])</code> with <code>existRule(rules[0])</code> or <code>existRule(rules[1])</code>, it return true or false depending on if the rule on that position matchs.</p>
  <p>Is there any way to get the result of the execution of <code>existRule(rules[i])</code> for all the elements of the array?</p>
  <p>I already tried <code>result := [existRule(rules[i])]</code> but it only return one element with true</p>