Please do send a PR. Although we should probably call it count_select?

Also note that instead of Enum.flat_map you want to use Enum.sum. Make sure
to test that scenario too. :)

On Thu, Nov 18, 2021 at 9:44 AM Rudolf Manusadzhian <rud.manusa...@gmail.com>
wrote:

> Registry provides Registry.select/2
> <https://hexdocs.pm/elixir/1.12/Registry.html#select/2> as an abstraction
> on top of `:ets.select/2` to select key, pid, and values using match
> specs.
>
> In one project we have a potential use case where we would like to only
> "select_count".
>
> Registry.count_match/4
> <https://hexdocs.pm/elixir/1.12/Registry.html#count_match/4> doesn't work
> for us, as it only matches on values under given key, while in our case we
> want to match on values under any key.
>
> Surely we can first get the list and then count items in it, but that
> won't be as nice as directly using :ets.select_count/2
> <https://www.erlang.org/doc/man/ets.html#select_count-2>
>
> Here
> <https://github.com/RudolfMan/elixir/compare/main...RudolfMan:add-registry-select_count>
> I put up together a version that does the same as `Registry.select/2` but
> uses `:ets.select_count` underneath.
>
> However, since match spec for "select_count" always assumes the third
> element to be `[true]` we could, probably only require the pattern and
> optional guards. Similar to the specs of Registry.count_match/4
> <https://hexdocs.pm/elixir/1.12/Registry.html#count_match/4>
>
> Any thoughts?
>
> --
> 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 elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/512a59bc-d9b2-4e97-85a0-f61033e9424fn%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/512a59bc-d9b2-4e97-85a0-f61033e9424fn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JpObFg4q-sKzQS%3DpAjYpDR0Uk-MYKdpV7r_Y_h%2Bx4asw%40mail.gmail.com.

Reply via email to