lists:zip / zip_with / unzip etc

Heinz Eriksson heinz.eriksson@REDACTED
Thu Jul 4 15:56:29 CEST 2002


I can't find any functions which does the same
as zip (Haskell, Python) or unzip/zipWith (Haskell).
Is this zip ok or is there som good function available
which I have missed?


ziph([H1|L1],[H2|L2], Z) -> 
    ziph(L1,L2,[{H1,H2}|Z]);
ziph([],L2, Z) -> 
    Z;
ziph(L1,[], Z) -> 
    Z.

zip(A,B) ->
    lists:reverse(ziph(A,B,[])).

For example
mean_list(A,B) ->
    [(U+L)/2.0 || {U,L} <- zip(A,B)].

2> mean_list([2.0,3.0], [1.0,2.0]).
[1.50000,2.50000]
3> 
   
/hz




More information about the erlang-questions mailing list