list handling functions

Vlad Dumitrescu <>
Thu Sep 18 21:23:48 CEST 2003


Hi,

Maybe tomorrow I will be ashamed to have asked a question whose answer is
obvious, but here it goes:

Are there any ways to simply express a 'map' (or similar) function that
iterates over several lists at once? I use something like

map2(Fun, A, B) ->
    map2(Fun, A, B, []).

map2(Fun, [], _, Res) ->
    lists:reverse(Res);
map2(Fun, _, [], Res) ->
    lists:reverse(Res);
map2(Fun, [Ha|Ta],[Hb|Tb],Res)->
    map2(Fun, Ta, Tb, [Fun(Ha, Hb)|Res]).

but this seems to be general enough to be found in a library. Or maybe list
comprehensions could be used in a clever way?

thanks in advance,
Vlad



More information about the erlang-questions mailing list