Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-docgen

Documentation publishing for Pudu: articles, API references, navigation, search, and static websites

0.1.0Apache-2.01

InstallClose

Inventory.pudu

Pudu35 lines1.0 KB

GitHub ↗
1/** @Inventory.Model.Module — stock items and their quantities */2module Inventory34/** @Inventory.Model.Item — one stocked product */5export type Item = {6  /// Stock keeping unit, unique per product.7  sku: Str,8  /// Units on hand.9  quantity: Int10}1112/** @Inventory.Model.Change — why a quantity moved */13export type Change = Received(Int) | Sold(Int) | Counted(Int)1415/// An item with no units on hand.16export fn empty(sku: Str) -> Item { Item{sku: sku, quantity: 0} }1718/// The item after a change is applied; a count replaces the quantity.19///20/// ## Examples21///22/// ```pudu23/// let item = Inventory.apply(Inventory.empty("A-1"), Inventory.Received(5))24/// ```25export fn apply(item: Item, change: Change) -> Item {26  match change {27    case Received(count) => Item{..item, quantity: item.quantity + count}28    case Sold(count) => Item{..item, quantity: item.quantity - count}29    case Counted(count) => Item{..item, quantity: count}30  }31}3233/// Largest quantity a single change may carry.34export const LIMIT: Int = 10000035