Skip to content

Instantly share code, notes, and snippets.

@seanmor5
Created June 21, 2023 00:45
Show Gist options
  • Save seanmor5/bb5d294edb2b7258afc8c41fc03d7e65 to your computer and use it in GitHub Desktop.
Save seanmor5/bb5d294edb2b7258afc8c41fc03d7e65 to your computer and use it in GitHub Desktop.
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