Skip to content

Feature request: Membership operator (probably called in) #2322

Open
@kelvinlamwh

Description

@kelvinlamwh

Please describe your feature request.
Inverse operator of contains, probably called in or something alike?

Describe the solution you'd like
If we have data1.yml like:
(please keep to around 10 lines )

- {item: 'Pizza', type: 'Food'}
- {item: 'Pasta', type: 'Food'}
- {item: 'Rose', type: 'Flower'}
- {item: 'Tulip', type: 'Flower'}
- {item: 'Hammer', type: 'Tool'}
- {item: 'Screwdriver', type: 'Tool'}

And we run a command:

yq 'filter(.type | in(["Tool", "Food"]))' data1.yml

it could output

- {item: 'Pizza', type: 'Food'}
- {item: 'Pasta', type: 'Food'}
- {item: 'Hammer', type: 'Tool'}
- {item: 'Screwdriver', type: 'Tool'}

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

yq 'filter(.type as $el | ["Tool", "Food"] | contains([$el]))' data1.yml

Additional context
jq also has the in operator

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions