Will prepare PR with functionality and documentation updates and post it as WIP once it is ready.
пʼятниця, 24 лютого 2017 р. 12:14:10 UTC+2 користувач José Valim написав: > > Hi Yurko, please send a pull request that adds support for guards. :) > > In the documentation we should make it clear that only the matchspec > variables $1, $2 and friends must be used. If you use $$ or $_ there is no > guarantee the representation will be kept. > > > > *José Valim* > www.plataformatec.com.br > Skype: jv.ptec > Founder and Director of R&D > > On Fri, Feb 24, 2017 at 8:41 AM, Yurko Hoshko <[email protected] > <javascript:>> wrote: > >> 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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/ef366cd6-bb81-434b-8249-5948b0e735eb%40googlegroups.com >> >> <https://groups.google.com/d/msgid/elixir-lang-core/ef366cd6-bb81-434b-8249-5948b0e735eb%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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/6d2d72cd-aed9-4891-8381-96facd6f8b9d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
