[erlang-questions] [erlang-question] How to comprehend two lists synchronously?
Dmitry Demeshchuk
demeshchuk@REDACTED
Fri Nov 18 06:49:41 CET 2011
My guess is you have to zip them together, or just write a
tail-recursed function:
map2(Fun, [H1 | T1], [H2 | T2]) ->
[Fun(H1, H2) | map2(Fun, T1, T2)];
map2(Fun, [], []) ->
[].
The second option definitely isn't a list comprehension, but it
requires less memory and has lesser complexity.
On Fri, Nov 18, 2011 at 9:45 AM, Barco You <barcojie@REDACTED> wrote:
> Dear Erlangers,
>
> I hope to get a list from two lists like this:
> [{a1,b1}, {a2,b2}, {a3,b3}] <- [a1, a2 a3], [b1, b2, b3].
> But if I use list comprehension, I got:
> 10> [{D1,D2} || D1 <- [a1,a2,a3], D2 <- [b1,b2,b3]].
> [{a1,b1},
> {a1,b2},
> {a1,b3},
> {a2,b1},
> {a2,b2},
> {a2,b3},
> {a3,b1},
> {a3,b2},
> {a3,b3}]
>
> So, my questions is how to comprehend list in synchronous way in order to
> get what I want, rather than to compose the elements from two lists in all
> possible situations.
>
> Thank you,
> Barco
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
--
Best regards,
Dmitry Demeshchuk
More information about the erlang-questions
mailing list