Skip to content

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

Notifications You must be signed in to change notification settings

karlonovak/genserver-shoppingcart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages