process-communication/lib/stack.ex
2023-07-03 13:51:47 +03:00

20 lines
332 B
Elixir

defmodule MyStack do
use GenServer
def start_link(args) do
GenServer.start_link(__MODULE__, nil, name: args[:name])
end
def init(_) do
{:ok, []}
end
def handle_info({:push, el}, state) do
{:noreply, [el] ++ state}
end
def handle_call(:pop, _from, [head | tail]) do
{:reply, head, tail}
end
end