Skip to content

Add ability to define custom predicate functions #497

Description

@neetle

Hi!

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.

Activity

  1. antonmedv commented on Dec 22, 2023

    @antonmedv
    Member

    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:

    nodesToArray(Nodes) | filter(.Name=="cat")
    
  2. locked and limited conversation to collaborators on Jan 2, 2024
  3. converted this issue into a discussion #508 on Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions