[erlang-questions] maps iterator

zxq9 zxq9@REDACTED
Tue Sep 29 10:32:48 CEST 2015


On Tuesday 29 September 2015 10:12:55 Sergej Jurečko wrote:
> Something like gb_trees:iterator_from
> If you're traversing the entire map then to_list is fine (which fold,map
> use). But if you wish to only traverse a subset of k/v pairs in a large map
> it is quite wasteful.

Map keys are unordered. GB tree keys are ordered.

If you are using maps then something like iterator_from already does not fit. But maybe you have some subset of keys you want to traverse? That is what maps:with/2 and maps:without/2 are for. (I have no idea how efficient with/2 or without/2 are in gigantic maps in R18 -- but I imagine these are the functions that will be optimized to death eventually if anything is, so it is what I would write code against today. Unless you actually do just need gb_trees...)

In some cases having maps:partition/2 would be nice, but there are no cases I can think of where an equivalent to iterator_from makes sense without either requiring a filter over the entire map's values to figure out what subset you want, or already having a sublist of keys you want to include or exclude from your traversal.

What am I missing?

-Craig



More information about the erlang-questions mailing list