Created
June 15, 2015 21:00
-
-
Save MonkeyIsNull/0c6d056fc163694ea70d to your computer and use it in GitHub Desktop.
Cart Example
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 Cart do | |
def start() do | |
{:ok, cart} = Agent.start(fn -> ["Seconds - by Bryan Lee O'Malley"] end) | |
cart | |
end | |
def print_cart(items) do | |
Enum.each(items, fn item -> IO.puts "Item: #{item}" end) | |
end | |
def show(cart) do | |
Agent.get(cart, fn(items) -> print_cart(items) end) | |
end | |
def add_item(cart, item) do | |
Agent.update(cart, fn(items) -> [item | items] end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment