Skip to content

Instantly share code, notes, and snippets.

@MonkeyIsNull
Last active November 4, 2015 02:20
Show Gist options
  • Save MonkeyIsNull/d70bf3cc15cfea961e2a to your computer and use it in GitHub Desktop.
Save MonkeyIsNull/d70bf3cc15cfea961e2a to your computer and use it in GitHub Desktop.
Catstore
defmodule Catstore do
def start() do
{:ok, store} = Agent.start(fn -> ["Biggles"] end)
store
end
def pr_cats(cats) do
Enum.each(cats, fn cat -> IO.puts cat end)
end
def show_cats(store) do
Agent.get(store, fn(cats) -> pr_cats(cats) end)
end
def add_cat(store, cat) do
Agent.update(store, fn(cats) -> [ cat | cats] end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment