This is not possible, because there are no Arrays in Elixir, but linked List
In Elixir, You don’t access list element by index, because it’s expensive.
This is not possible, because i is mutated
Instead, You can have functions that transform input into output.
defmodule Demo do
def fib(0), do: 0
def fib(1), do: 1
def fib(n), do: fib(n - 1) + fib(n - 2)
end
and if You want to cumulate, You can enumerate a range from 0 to 10 and pass the implementation details.
Enum.map(0..10, & Demo.fib(&1))
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
This is not efficient, as the result is recalculated. But You can make it better with recursion.


















