1

I whish to combine two arrays of Boolean value using AND.

For example: a1 := [true, true, false], a2 := [false, true, false].

the resulting AND operation:

a3 = a1 AND a2 would be [false, true, false]

1 Answer 1

0

To get to the desired output, one would need to basically implement a Boolean "AND" function implementing each set of possible inputs as functions and return the result and build the resulting array using a comprehension:

policy.rego

package example

import rego.v1

a1 := [true, true, false]
a2 := [false, true, false]
a3 := [b | b := boolean_and(a1[i], a2[i])]

boolean_and(x, y) := z if {
    is_boolean(x)
    is_boolean(y)
    x
    y
    z := true
}

boolean_and(x, y) := z if {
    is_boolean(x)
    not x
    z := false
}

boolean_and(x, y) := z if {
    is_boolean(y)
    not y
    z := false
}

The resulting output would look like:

opa eval -d policy.rego "data.example"

{
  "result": [
    {
      "expressions": [
        {
          "value": {
            "a1": [
              true,
              true,
              false
            ],
            "a2": [
              false,
              true,
              false
            ],
            "a3": [
              false,
              true,
              false
            ]
          },
          "text": "data.example",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.