[Proposal]: Registry.select_count/2

70 views
Skip to first unread message

Rudolf Manusadzhian

unread,
Nov 18, 2021, 3:44:16 AM11/18/21
to elixir-lang-core
Registry provides Registry.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 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 

Here 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

Any thoughts?

José Valim

unread,
Nov 19, 2021, 6:17:35 AM11/19/21
to elixir-l...@googlegroups.com
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. :)

--
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.

Rudolf Manusadzhian

unread,
Nov 20, 2021, 12:06:17 AM11/20/21
to elixir-lang-core
Thank you, José! 
I made PR #11405

Reply all
Reply to author
Forward
0 new messages