Skip to content

Conversation

@anderseknert
Copy link
Member

@anderseknert anderseknert commented Jan 17, 2026

Originally meant to be array.concat_n, but this name is better as the behavior of this function differs from array.concat — namely that array.flatten accepts any type of valued in the input array. Only arrays are however flattened, and the rest are appended directly to the flattened output.

Note that this function only flattens at the topmost level of the inpu array — not recursively! Which a cursory look at a few other languages suggested was the common case. But if others feel we should flatten more, I'm happy to make an update.

The C code for a Wasm implementstion here is cowboy coded, and I did not manage to run the tests on my machine due to some docker <-> container differences. I mostly just imitated the existing code in the array category. I doubt it'll work on the first try, but only CI can judge me.

Also:

  • Remove opa fmt step from the Rego CI step, as this is done by Regal anyway a little later in the list of tasks.
  • Replace some hard-coded docker nmes in the Makefile with $(DOCKER)
  • Added name of built-in function missing to the unsupportedBuiltinErr error, as it has happened a few times now that I've used := in a query, and had no clue what built-in it referred to.

Fixes #8226

Originally meant to be `array.concat_n`, but this name is better
as the behavior of this function differs from `array.concat` —
namely that `array.flatten` accepts any type of valued in the
input array. Only arrays are however flattened, and the rest
are appended directly to the flattened output.

Note that this function only flattens at the topmost level of
the inpu array — not recursively! Which a cursory look
at a few other languages suggested was the common case. But if
others feel we should flstten more, I'm happy to make an update.

The C code for a Wasm implementstion here is cowboy coded, and
I did not msnage to run the tests on my machine due to some
`docker` <-> `container` differences. I mostly just imitated
the existing code in the array category. I doubt it'll work
on the first try, but only CI can judge me.

Also:
- Remove `opa fmt` step from the Rego CI step, as this is done by
  Regal anyway a little later in the list of tasks.
- Replace some hsrd-coded `docker` nmes in the `Makefile` with `$(DOCKER)`
- Added name of built-in function missing to the unsupportedBuiltinErr
  error, as it has happened a few times now that I've used `:=` in a
  query, and had no clue what built-in it referred to.

Fixes open-policy-agent#8226

Signed-off-by: Anders Eknert <anders.eknert@apple.com>
@netlify
Copy link

netlify bot commented Jan 17, 2026

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit ccf35f2
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/696ad19d343b6400098c0101
😎 Deploy Preview https://deploy-preview-8232--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@anderseknert
Copy link
Member Author

Lol, my C code seems to work? All the Wasm tests are passing.

ig9OoyenpxqdCQyABmOQBZDI0duHk2QZZmWg2Hxd4ro-495190217

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks


var ArrayFlatten = &Builtin{
Name: "array.flatten",
Description: "Non-recursively unpacks array items in arr into the flattened array. Other types are appended as-is.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we'll want a recursive variant, too? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. So we're back to calling it array.concat_n then? 🙂 I do like not having to ceremonially wrap things in array literals to have them appended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with either. Let's flip a mobile phone. (cc @johanfylling)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It came up screen-up📱

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding array.flatten built-in function

3 participants