Proposal: ets:select_take?

Fred Youhanaie fly@REDACTED
Wed Jul 15 14:15:54 CEST 2020

Hi Borja

Would iterating over the list of objects with ets:delete_object/2 help?

for example:

lists:foreach(fun (Obj) -> ets:delete_object(table, Obj) end, Objects)


On 15/07/2020 11:46, Borja de Regil wrote:
> 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