Hi,
It makes sense
As you don’t pass initial accumulator, then the first element of the list was taken and the first element on output will be the same as on input - {-1, 3}.
Then, on first iteration
[b: 1, e: 5, x: 3]
b and e are from the second element of the list and x is from accumulator which is the first element of the list.
Then you build new two-element tuple which is {3, 5}, it is used as second value in output list and as accumulator for the next element.
Then on the next iteration
[b: 10, e: 15, x: 5]
b and e are from the last element and x is from accumulator. Newly built tuple is {10, 15}, it is used as third element.
So, we have
[{-1, 3}, {3, 5}, {10, 15}]
Maybe, it would be easier for you if we reimplement Enum.scan using Enum.map_reduce:
def my_scan([], _callback), do: []
def my_scan([head | tail], callback) do
{map_result, _reduce_result} = Enum.map_reduce(tail, head, fn x, acc ->
result = callback.(x, acc)
{result, result}
end)
[head | map_result]
end






















