Last active
November 4, 2015 02:20
-
-
Save MonkeyIsNull/d70bf3cc15cfea961e2a to your computer and use it in GitHub Desktop.
Catstore
This file contains 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 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