i am doing excise with these objective:
Based on the Calculator example, define a multiply operation taking two parameter values and return the product.
Modify the Calculator to count how many multiplications it has done for its clients.
Followings are examples of call
> GenServer.call(calc, {:mult, 4, 2})
{1, 8}
> GenServer.call(calc, {:mult, 3, 9})
{2, 27}
> GenServer.call(calc, {:mult, 11, 11})
{3, 121}
and here is what i done for now :
define a multiply operation taking two parameter values and return the product.
still left the counter part anybody know how to do it?
defmodule Calculator do
use GenServer
def handle_call({:mult5, n1, n2}, _from, state) do
{:reply, n1 * n2 , state}
end
end
here is the step to run the Calculator.exs
iex(1)> c "Calculator.exs"
iex(2)> {:ok,calc} = GenServer.start_link(Calculator, [ ])
{:ok, #PID<0.119.0>}
iex(3)> GenServer.call(calc, {:mult5, 4,2})
8
thanks