%% Applies Fun/2 to each corresponding pair of elements from lists L1
%% and L2. Returns a list of results.
lists_map2(Fun, L1, L2) ->
lists:reverse(lists_map2_(Fun, L1, L2, [])).
lists_map2_(_, [], _, RevLoP) ->
RevLoP;
lists_map2_(_, _, [], RevLoP) ->
RevLoP;
lists_map2_(Fun, [H1|T1], [H2|T2], RevLoP) ->
lists_map2_(T1, T2, [Fun(H1, H2) | RevLoP]).
%% Iterates over binaries.
binaries_foreach(_, << >>) ->
ok;
binaries_foreach(Fun, Bin) ->
Bin1 = Fun(Bin),
binaries_foreach(Fun, Bin1).
binaries_fold(_, Acc, << >>) ->
Acc;
binaries_fold(Fun, Acc, Bin) ->
{Acc1, Bin1} = Fun(Bin, Acc),
binaries_fold(Fun, Acc1, Bin1).
%% A Perl-style join --- concatenates all strings in Strings,
%% separated by Sep.
perl_join(Sep, Strings) ->
perl_join_(Sep, Strings, []).
perl_join_(_, [], Acc) ->
lists:append(lists:reverse(Acc));
perl_join_(Sep, [Str | Rest], []) ->
perl_join_(Sep, Rest, [Str]);
perl_join_(Sep, [Str | Rest], Acc) ->
perl_join_(Sep, Rest, [Str, Sep | Acc]).
|