Skip to content

Does array in REGO support the operation like append and extend #77

Discussion options

You must be logged in to vote

Hi @lemonshir!

Rego variables and values are immutable, so there's no way to modify them directly. Like most languages with immutable values and vars, you can however use functions that return new values or collections to achieve the same outcome. For your example of appending to an array, you can use the array.concat built-in:

a := [1, 2, 3]
b := [4, 5, 6]
c := array.concat(a, b)

# c == [1, 2, 3, 4, 5, 6]

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anderseknert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #76 on December 12, 2021 16:33.