cel-go icon indicating copy to clipboard operation
cel-go copied to clipboard

List helper functions

Open chancez opened this issue 1 year ago • 0 comments

Change I'm looking at whether or not CEL could be used as a DSL for an existing gRPC based query API. For a query API, we may need to operate on a list of objects and perform various operations. Some macros like filter, exists, and map already exist for some use-cases, and I would like to see if we could add additional functions that operate on lists.

Example

  • myList.slice(start, end) could slice a list, much like in Go or Python via: mylist[start:end].
  • myList.first(n) could take the first elements from a list.
  • myList.last(n) could take the last elements from a list.

Any many more could be considered, but at the moment, these 3 are the first ones I'm thinking about.

Alternatives considered

This could be handled outside of CEL, but being able to manipulate lists would be very useful for using CEL in a query language.

I wrote a quick MVP of list.slice here: https://github.com/google/cel-go/compare/master...chancez:cel-go:pr/chancez/slice_function

chancez avatar Jun 22 '23 22:06 chancez