Proposal: ets:select_take?
Borja de Regil
borja.deregil@REDACTED
Wed Jul 15 12:46:05 CEST 2020
Hi everyone, it’s been a couple of times already that I’ve wished for something like ets:take/2 that accepts a match specification like ets:select or ets:match.
Currently, ets:select_delete returns the number of deleted items, but it’s possible you want to first to something with those items _before_ deleting them. In this case, one has to resort to something like the following:
Objects = ets:select(table, [{ MatchSpec, MatchCond, MatchReturn }]),
%% do something with objects
ets:select_delete(table, [{ MatchSpec, MatchCond, [true] }]).
It seems wasteful to perform two scans on the table in this case. But perhaps this pattern is not common enough in the wild?
Looking forward to hear your opinion!
Cheers,
Borja
More information about the erlang-questions
mailing list