Skip to content

Instantly share code, notes, and snippets.

@jmsevold
Created February 16, 2016 00:41
Show Gist options
  • Save jmsevold/ca5a04587931e4a147f1 to your computer and use it in GitHub Desktop.
Save jmsevold/ca5a04587931e4a147f1 to your computer and use it in GitHub Desktop.
defmodule TodoAgent do
def create_list do
Agent.start_link(fn -> [] end)
end
def add_todo(todo_list, todo) do
Agent.update(todo_list, fn(todos) -> [todo | todos] end )
end
def remove_todo(todo_list, todo) do
Agent.update(todo_list, fn(todos) -> Enum.filter(todos, fn(item) -> item != todo end) end)
end
def display_list(todo_list) do
Agent.get(todo_list, fn(todos) -> todos end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment