Expression Language Misunderstanding: indexOf()

I have the following Expression Structure:

{
"Valves":[
0:Open
1:Closed
2:Closed
...
]

I want to return true if any of the valves are open

When I do the following:

{value}["Valves"][0] = "Open"

Result: true

When I do the following:

indexOf({value}["Valves"],"Open")

Result: -1

Can someone explain what I am doing wrong or what assumptions I have that are incorrect? I also tried checking the typeOf({value}["Valves"][0] and it is a string...

{value}["Valves"] is not {value}["Valves"][0].

indexOf() does not find the index of a string in a list, it finds the index of a substring in a string.

What are you trying to accomplish?

I would use my Toolkit's where() iterator, wrapped in len(). Like so:

len(
    where(
        {value}['Valves'],
        it() = 'Open'
    )
) > 0

(I would also collapse your expression structure to use my asList() and nest it directly in the final expression. Avoid the transform overhead.)

Oh duh, that makes sense. I am looking for if any of the values are "Open" then I want to return True

Is a native clean solution not available?

No. My Toolkit closes many gaps in the native expression language, especially when dealing with lists, maps, and variable-length objects.

I'm bummed that there is no clean native solution. I am going to install your module to test it out, but I am unable to do a gateway restart at this time so I cannot test it out. Thank You for your work on this module.

Probably the best you can get in a single binding without Phil's module, is to add a script transform.

return any(valve == 'Open' for valve in value)

Phil's module is worth it, you will not know what you did without it.

:blush:

(Worth the bureaucratic trouble, if any, only, as it is free.)