Hello all.
I am trying to find a process via function Registry.select/2. Guards seem to work for comparison operators like :>. But I would like to implement a guard that checks if a value is in a list using the in/2 operator.
The documentation for the guards states that it should be possible:
https://hexdocs.pm/elixir/guards.html
The following code has two guards. The first one works, but the second one fails with an error: * 2nd argument: not a valid match specification
Registry.select(Registry, [
{
# match_pattern
{
# key
{:id, :"$1"},
# pid
:"$2",
# value - username is a string, roles is a list of strings
%{username: :"$3", roles: :"$4"}
},
# guards
[
# this guard works
{:=, :"$3", "test_user"},
# this guard fails with an error: * 2nd argument: not a valid match specification
{:in, :"$4", ["admin", "support"]}
],
# body
[%{username: :"$3", roles: :"$4"]
}
])
Is the “in” operator supported in the Registry.select function. If so, how do I use it?