Loading Bazaar…
An RPG item shop — built entirely in Axon
// Interface: structural contract interface Tradeable { name: string price: int describe: fn() -> string } // Generic filter helper fn keep_if<T>( items: T[], pred: fn(T) -> bool ) -> T[] = items.filter(pred) // Generic map helper fn transform<T, U>( items: T[], f: fn(T) -> U ) -> U[] = items.map(f)
// Item category as tagged union type Category = | Weapon | Armor | Potion | Relic | Scroll // Core typed record record Item { name: string category: Category rarity: string price: int power: int lore: string } // Generic sort-by-key fn order_by<T>( items: T[], key: fn(T) -> any ) -> T[] = items.slice().sort(...)
// let infer — model resolves type fn apply_filters( state: AppState ) -> Item[] { let infer a = by_category( state.all_items, state.filter_cat ) let infer b = by_rarity(a, state.filter_rar) let infer c = search_items(b, state.search) let infer sorted = apply_sort(c, state.sort_key) sorted }
// Immutable app state record record AppState { all_items: Item[] cart: Item[] filter_cat: string filter_rar: string sort_key: string search: string } // Type-safe add-to-cart fn buy_item(name: string) { let infer found = state.all_items.filter( i => i.name == name) // state is always replaced, // never mutated in-place }