defmodule Todo do use GenServer def init(tasks // "") do {:ok, tasks} end def handle_cast({:add, task}, tasks) do {:noreply, tasks <> " | " <> task} end def handle_cast({:remove, task}, tasks) do {:noreply, tasks |> String.replace("| #{task}", "")} end def handle_call(:all, _from, tasks) do {:reply, tasks, tasks} end end # {:ok, pid} = GenServer.start(Todo, "foo") # tasks = GenServer.call(pid, :all) # GenServer.cast(pid, {:add, "bar"}) # GenServer.cast(pid, {:remove, "bar"}) ## TODO # Encapsolate the GenServer logic in the module