-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contains as a new Test (flipped operation of in) #1766
Comments
FWIW, we needed this a while back in ansible, and added our own in ansible/ansible@f728f2b |
I would like this, coming from a dbt project! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since 2.10 there is the
in
test where I can filter all elements of a list on whether they occur in another container like so:[1,2,2,4,5,6,7] | select('in', [2,6]) | list
returns[2,2,6]
. The reverse operation is also useful.In my example I had a list of TV episode names and wanted only to show those containing a specific word. I would want the following:
['Mike','Joe','Michael'] | select('contains', 'Mi') | list
returns['Mike','Michael']
Writing the
for
-loop was no option for me, as I needed to select a single entry using| random
in the same expression (home automation is a bit finicky).Other solutions I've thought about were a test that allows to regex-check a string (this would also cover the
startswith
andendswith
cases, and is in general very versatile, but restricted to strings), or the higher-order functionflip
(rejected in #906) to just flip the arguments of the already existingin
filter. I think thecontains
filter is useful, as it seems to be the only binary operator that's missing. There are tests fora < b
and if I want the flipped version, there is a test fora >= b
. There is a test fora in b
but theb in a
test is missing.I am happy to write the PR myself. That's not too too much work. The contributing guideline suggested though, that an issue is opened before any time is wasted for unwelcome features. :)
The text was updated successfully, but these errors were encountered: