Hello everyone.
There is a small proposal for improvement in Registry.match/3 .
At the moment it does not support ETS guard conditions, which could be
quite useful.
Current behavior:
@spec match(registry, key, match_pattern :: atom() | tuple()) :: [{pid, term}]
def match(registry, key, pattern) when is_atom(registry) do
spec = [{{key, {:_, pattern}}, [], [{:element, 2, :"$_"}]}]
...
end
Second element of spec list is a list of guards which is empty and
non-changeable at the moment.
What we could do instead is allow passing additional guards for more
precise lookup.
So it would be something like:
@spec match(registry, key, match_pattern :: atom() | tuple(), guards ::
list()) :: [{pid, term}]
def match(registry, key, pattern, guards \\ []) when is_atom(registry) and
is_list(guards) do
spec = [{{key, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}]
...
end
Example of guard list for checking if pattern variable is greater then 1:
[{:>, :"$1", 1}]
It is a bit ugly syntax though - so it would be nice to hear if someone has
better ideas to do, as well as is this feature useful at all.
Thanks :)
P.S. Link to Registry.match/3 on GitHub: GitHub
<https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/registry.ex#L470-L487>
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/ef366cd6-bb81-434b-8249-5948b0e735eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.