Created
June 21, 2023 00:45
-
-
Save seanmor5/bb5d294edb2b7258afc8c41fc03d7e65 to your computer and use it in GitHub Desktop.
This file contains 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
main = fn -> | |
cmd = IO.gets("Enter a command: ") |> String.trim() | |
case String.split(cmd) do | |
["show"] -> | |
todos = Process.get(:todos) || [] | |
IO.puts(Enum.join(todos, "\n")) | |
["create" | rest] -> | |
todos = Process.get(:todos) || [] | |
Process.put(:todos, [Enum.join(rest, " ") | todos]) | |
[action, idx] when action in ~w(complete delete)s -> | |
# cheating | |
todos = Process.get(:todos) || [] | |
{idx, _} = Integer.parse(idx) | |
new_todos = List.delete_at(todos, idx) | |
Process.put(:todos, new_todos) | |
["exit"] -> | |
Process.exit(self(), :kill) | |
_ -> | |
IO.puts("Invalid command") | |
end | |
end | |
Stream.repeatedly(fn -> main.() end) |> Stream.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment