[Feature Request] `list.sum()` function
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
Hi @haines! The team is working hard to get ready for the v1 release of protovalidate, so we likely won't be able to visit this until after that.
That said, This might be a better question to have on google/cel-spec to add a more generic reduce macro instead.
Yep, it'd be great to get reduce in upstream. There is an issue on the CEL spec already (https://github.com/google/cel-spec/issues/143) but unfortunately it's been sitting there for about 5 years, so I'm not super optimistic about the prospects of getting it in any time soon.
If you'd consider adding a sum function to protovalidate post-1.0, that would be much appreciated!