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
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 and endswith cases, and is in general very versatile, but restricted to strings), or the higher-order function flip (rejected in #906) to just flip the arguments of the already existing in filter. I think the contains filter is useful, as it seems to be the only binary operator that's missing. There are tests for a < b and if I want the flipped version, there is a test for a >= b. There is a test for a in b but the b 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:
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: