I am new to Elixir and was reading through a book and doing some examples. Here is the piece of code that makes me ask question here:
defmodule Sequence.Server do
use GenServer
def init(initial_number)do
{:ok,initial_number}
end
def handle_call(:next_number, _from, current_number)do
{:reply, current_number,current_number+1}
end
end
As I know the init function is called when the server is being initialized and we are defining some parameter - which will be the initial state of the server. The thing that makes me confused is that how current_number and the initial_number are related to each other, I mean nowhere in the code we are saying something like that
current_number = initial_number
Because when I call GenServer.call(some_process_id, :next_number) it starts from 100 for example if the parameter to start_link was 100. How does Elixir understands that it must start from 100 when we dont have any mapping between the initial state and the current_number parameters