Skip to content

[Feature Request] list.sum() function #380

@haines

Description

@haines

Feature description:
Add sum function for numeric lists.

Problem it solves or use case:
I want to limit the maximum total size of a repeated File files field, where the File message has a bytes contents field. Without a sum function (or a more general reduce macro), I can't.

I'd like to be able to write a rule like

this.map(file, file.contents.size()).sum() <= 52428800

Proposed implementation or solution:

Add a function to the CEL runtime

<list<T>>.sum() <T>, T must be a numeric type or a duration

Contribution:

I would be happy to help implement this.

Examples or references:

sum is implemented in Kubernetes' CEL extensions: https://pkg.go.dev/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/library#Lists

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions