https://github.com/perty/elm-shopping
A little example in Elm. Inspired by the "Grokking Simplicity" book.
https://github.com/perty/elm-shopping
Last synced: 3 months ago
JSON representation
A little example in Elm. Inspired by the "Grokking Simplicity" book.
- Host: GitHub
- URL: https://github.com/perty/elm-shopping
- Owner: perty
- Created: 2020-03-11T11:25:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-12T12:39:25.000Z (over 6 years ago)
- Last Synced: 2025-03-12T07:44:35.378Z (over 1 year ago)
- Language: Elm
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# elm-shopping
A little example in Elm. Inspired by the ["Grokking Simplicity"](https://www.manning.com/books/grokking-simplicity) book.
So the Javascript in the book had some horrible things like "find in DOM" and imperatives such as "update icons".
In Elm, the view is simply a calculation (pure function) of the data (application state). So no need to find things in the DOM
to manipulate. With modules, it is possible to put calculations related to a shopping cart in a separate module.
Note how the current design has items that are in the product catalog `CatalogItem`and items in the cart `ShoppingCartItem`.
They are similar but different. The `addItem` function accepts anything with an id, description and a price.
Hence the `SomeItem` type alias internally.
`type alias SomeItem a =
{ a
| id : Int
, description : String
, price : Money
}`
## Money
The representation of money is designed for run-time handling of different currencies.
This is a bit unlike I would do it and I started out with a design with phantom types to represent money. But then
the shopping cart would need to know its currency at compile-time. Deciding the currency in run-time is flexible
but does not gurantee as much as compile-time. What if we add items with prices in different currencies?
## Business rules
All business rules are collected in the `Business` directory. Currently, there is only one
rule, the threshold for free shipping as of chapter 4 in the book.
By doing this, any rule usage can be found instead of being sprinkled throughout the
code.