An open API service indexing awesome lists of open source software.

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.

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.