Thank you, José! I made PR #11405 <https://github.com/elixir-lang/elixir/pull/11405>
On Friday, November 19, 2021 at 3:17:35 AM UTC-8 José Valim wrote: > 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.ma...@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-co...@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/0fd0b329-c444-4117-ad77-beea0859013fn%40googlegroups.com.