Created
February 16, 2016 00:41
-
-
Save jmsevold/ca5a04587931e4a147f1 to your computer and use it in GitHub Desktop.
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 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