[erlang-questions] maps iterator

Michael Truog <>
Mon Sep 28 22:54:56 CEST 2015


On 09/28/2015 12:54 PM, Sergej Jurečko wrote:
> Are maps ever going to get an iterator?
You could use something like this:

maps_itera(F, A, Map)
     when is_function(F, 4) ->
     Fold = fun(K, V, {Afold, Itr}) ->
         ItrA = fun(Anew) -> {Anew, Itr} end,
         case Itr(K, V, Afold, ItrA) of
             {_, Itr} = Iteration ->
                 Iteration;
             _ = Last ->
                 exit({maps_itera_last, Last})
         end
     end,
     try maps:fold(Fold, {A, F}, Map) of
         {Last, F} ->
             Last
     catch
         exit:{maps_itera_last, Last} ->
             Last
     end.

Then you define a function:
F = fun(K, V, A, Itr) ->
% if you want to iterate, call Itr(Anew)
% if you want to stop, just have the last evaluation be Anew
end

>
> Sergej
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150928/06128027/attachment.html>


More information about the erlang-questions mailing list