I am passing a function to Enum.reduce
as follows to get 24
Enum.reduce([1,2,3,4], &(&1 * &2)) #=> 24
If I have a nested list in which I would like to multiply each nested element and sum them together. For example in [[1,2],[3,4]]
I would like to perform [[1*2] + [3*4]]
to get 14
, is there a way to do it (using anonymous functions)
This is what I tried (knowing its incorrect) and I got nested captures via & are not allowed
. I am trying to understand the required mental model when using Elixir
Enum.reduce([[1,2],[3,4]], &(&(&1 * &2) + &(&1 * &2)))
&
operator to create too complex anonyomus functions, since you will end up with hard to debug, understand code. – coderVishal