Skip to content

[Feature Request] Helper function to get the unique values from a list #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
milas opened this issue Jan 31, 2025 · 0 comments
Open
Labels
Feature New feature or request

Comments

@milas
Copy link

milas commented Jan 31, 2025

Feature description:
A to_unique() -> list (or equivalent) function to accompany the unique() -> bool CEL helper function.

Supported today:

[1, 1, 2, 3, 3 ].unique()      # false

Proposal:

[1, 1, 2, 3, 3 ].to_unique()   # [1, 2, 3]

.to_unique().unique() is always true.

Problem it solves or use case:
unique() is a helpful protovalidate addition for something you can't do in CEL otherwise. I want the intermediate form, i.e. the set of unique values, exposed to do even more!

Contribution:
I can likely contribute the PR for this - just let me know re: to_unique() naming at least if no other major concerns.

Examples or references:
Example: Ensure all items in a collection are all siblings

this.collection.map(x, x.parent_id).to_unique().size() == 1

Example: Ensure all structpb.Value items are of the same type

google.protobuf.Value value = 1 [
  (buf.validate.field).cel = {
    id: "repeated.same_type",
    message: "all values must be of same type",
    expression: "type(this) != list || this.map(v, type(v)).to_unique().size() <= 1"
                                          //               ^^^^^^^^^^^^^
                                          //             my hopes & dreams
  }
];

(can you guess this is the specific use case I have in mind? 😉)

@milas milas added the Feature New feature or request label Jan 31, 2025
@milas milas changed the title [Feature Request] [Feature Request] Helper function to get the unique values from a list Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant