Reputation: 128
I'm trying to do a sum of two list, for example:
1> example:sum([4,5], [6,7])
[10,12]
Upvotes: 1
Views: 574
Reputation: 1369
The Built-In Function zipwith/3
in lists
module can solve your problem
> lists:zipwith(fun(X, Y) -> X+Y end, [4, 5], [6, 7]).
[10, 12]
Upvotes: 3
Reputation: 3202
I like the answer @doan-bui provided. It could also be solved using zip/2
and a list comprehension.
> [X+Y || {X,Y} <- lists:zip([4, 5], [6, 7]).
[10, 12]
Upvotes: 1