-
Notifications
You must be signed in to change notification settings - Fork 54
Closed
Labels
FeatureNew feature or requestNew feature or request
Description
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? 😉)
Metadata
Metadata
Assignees
Labels
FeatureNew feature or requestNew feature or request