Last active
March 19, 2019 23:50
-
-
Save sofakingworld/a5635919d87b864f6364592a62ef8c1d to your computer and use it in GitHub Desktop.
StackImp#2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule StackImp do | |
def pop(list) do | |
# Возвращает кортеж с вынутым значением, и остатком списка. | |
# подходит в качестве ответа для генсервера | |
List.pop_at(list, 0) | |
end | |
def push(list, item) do | |
new_list = [item | list] | |
# Дублирем значения в кортеже, т.к. первое будет использоваться | |
# в качестве ответа, а второе - новое состояние генсервера | |
{new_list, new_list} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment