I have a list like [2,10,3,5]
. Now i want to add numbers inside list i.e 2+10+3+5 = 20
. I should get 20
as the result, how can i do that??
thank you
… or more generically:
Enum.reduce [2,10,3,5], &Kernel.+/2
-
Enum.reduce [2,10,3,5], 0, &Kernel.+/2
List.foldl [2,10,3,5], 0, &Kernel.+/2
2 Likes
You can just do &+/2
.
2 Likes
Sure, it may be harder to look up / Google though.
I’ll try in the future to include mentioning it for completeness.
1 Like