add test stack
This commit is contained in:
parent
8293234a24
commit
e53f5ef04d
3 changed files with 60 additions and 0 deletions
19
lib/stack.ex
Normal file
19
lib/stack.ex
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue