You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add ability to define custom predicate functions #497
I'm currently working on a project that would like to use this as the primary language to build filters for it's frontend.
At the moment, we're hoping to allow users to write queries like Nodes | filter(.Name=="cat"). We're currently facing an issue though, as Nodes isn't a slice. This leads to issues like array.Len() causing panics in the VM every time we hit an OpBegin.
As we don't control the layout/go type of the data we're passing into expr, would you be against defining some way to implement functions that take custom predicates?
Looking forwards, this could also be a good place to look into support for the changes proposed in golang/go#61898.
Yes, it is possible to implement next expression, even if Nodes is not an array.
Nodes | filter(.Name=="cat")
To do it you can create a patcher which will be wrapping Nodes inside filter into a helper function. The helper function will transform Nodes to an array.
After the patcher resulting code should look like this:
Activity
antonmedv commentedon Dec 22, 2023
Yes, it is possible to implement next expression, even if
Nodesis not an array.To do it you can create a patcher which will be wrapping Nodes inside filter into a helper function. The helper function will transform Nodes to an array.
After the patcher resulting code should look like this: