beck / module documentedSource

Module documented

Interface digest 5e3d4b05eda38000c6745c9cb47ab260 · 9/9 published names documented

Types

Money

type Money = newtype[Int]

An amount of money in minor units — pence, cents — never a float.

A newtype rather than an alias, so it cannot be passed where a plain `Int` is expected: §3.1's "ids of different entities must not be interchangeable" is about amounts too.

Line

model Line

One line on an order: a product, bought some number of times.

Field
sku: Str

What was bought. Opaque here; the catalogue owns the meaning.

quantity: Int

How many. A line with a quantity of zero is legal and contributes nothing.

unit_price: Money

The price of one unit when the line was written, not the price today.

Adjustment

union Adjustment

What changes the amount payable, beyond the lines themselves.

Variant
Discount(amount: Money)

A flat reduction.

Shipping(cost: Money)

Carriage. Free delivery is `Shipping(Money(0))` rather than the absence of this variant.

Names

NameRuns onEffects
apply_adjustmentanyno effects
chargeableanyno effects
chargeable_countanyno effects
line_totalanyno effects
minor_unitsanyno effects
payableanyno effects

apply_adjustment

apply_adjustment(running: Int, adjustment: Adjustment) -> Int

defon anyno effects

What one adjustment does to a running total — a discount subtracts, shipping adds.

chargeable

chargeable(lines: list[Line]) -> list[Line]

defon anyno effects

The lines that would actually be charged for — quantity above zero.

`filter_list` is effect-polymorphic (§3.2), so this is pure exactly because its predicate is.

chargeable_count

chargeable_count(lines: list[Line]) -> Int

defon anyno effects

How many lines would be charged for.

line_total

line_total(line: Line) -> Int

defon anyno effects

What one line costs: unit price times quantity.

minor_units

minor_units(m: Money) -> Int

defon anyno effects

Read the minor units out of a `Money`.

The one place the newtype is opened, so a change of representation is a change here rather than everywhere an amount is arithmetic.

payable

payable(line: Line, adjustment: Adjustment) -> Int

defon anyno effects

The amount payable for one line under one adjustment.