Trying to understand how Elixir makes Enum.reduce, I connected it to look at the output. I don’t understand why it first executes the second element of the list, and not the first, and then it executes all the rest independently.
iex (30)> Enum.reduce([1,2,3,4], &(IO.puts("a#{&1} b#{&2}")))
a2 b1
a3 bok
a4 bok
(A and b to check order)
Looking at the source, I think it translates into
:lists.foldl(&IO.puts("a#{&1} b#{&2}"), 1, [2,3,4])
giving the same result.
where 1 is the initial battery, and if I gave him a function that gave him something to copy, I would say something interesting, except for the "side".
Inverting these initial values, however, strikes me as an odd behavior. How should I think about decreasing the implementation?
source
share