Suggestion: New table iterators
Bjorn Gustavsson
bjorn@REDACTED
Thu Oct 19 10:39:29 CEST 2000
I suggest that we add
ets:foldl(Fun, Acc, Table)
ets:foldr(Fun, Acc, Table)
dets:foldl(Fun, Acc, Table)
dets:foldr(Fun, Acc, Table)
mnesia:foldl(Fun, Acc, Table)
mnesia:foldr(Fun, Acc, Table)
for iteration over tables.
The difference between the foldl/3 and foldr/3 is the order in which the
table elements are accessed. foldl/3 accesses from the first element to
the last, while foldr/3 accesses the element from last to to first.
Both functions are tail-recursive. The order is important only for ordered tables.
There is no need for map/2 or filter/3 functions, because they can easily
be simulated with the fold functions:
my_tab2list(T) ->
ets:foldr(fun (E, Acc) -> [E|Acc] end, [], T).
Besides, the reasonable semantics for map/2 and filter/3 would be that
they modified the ets table or returned a new ets table, something we
we are no prepared to implement now, but might be implemented in a future version.
Any comments?
/Björn
--
Björn Gustavsson Ericsson Utvecklings AB
bjorn@REDACTED ÄT2/UAB/F/P
BOX 1505
+46 8 727 56 87 125 25 Älvsjö
More information about the erlang-questions
mailing list