add test stack

This commit is contained in:
Timofey Khoruzhii 2023-07-03 13:51:47 +03:00
parent 8293234a24
commit e53f5ef04d
3 changed files with 60 additions and 0 deletions

19
lib/stack.ex Normal file
View file

@ -0,0 +1,19 @@
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