Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 690 Bytes

README.md

File metadata and controls

34 lines (22 loc) · 690 Bytes

ShoppingCart GenServer Example

Demonstrates GenServer usage in Elixir with a simple ShoppingCart as well as using Agent as a state recovery mechanism.

Usage

iex -S mix         
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)> alias ShoppingCart.Cart
ShoppingCart.Cart

iex(2)> Cart.show_articles
%{}

iex(3)> Cart.add_article(:shirt)
:ok

iex(4)> Cart.add_article(:shirt)
:ok

iex(5)> Cart.add_article(:jeans)
:ok

iex(6)> Cart.show_articles      
%{jeans: 1, shirt: 2}

iex(7)> Cart.remove_article(:shirt)
%{jeans: 1, shirt: 1}