Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Text · 25 lines · 825 B · at 358de06

// Written against the migrated module: findItem and firstLow now return// Option, parseQty returns Result, and Item is plain data plus functions.import { createItem, itemLabel, findItem, firstLow, parseQty } from "./inventory.tsus";const stock = [createItem("tea", 12), createItem("cocoa", 2)];console.log(match (findItem(stock, "tea")) {  Some(item) => itemLabel(item),  None => "no tea",});console.log(findItem(stock, "coffee").isNone());console.log(firstLow(stock).map(itemLabel).unwrapOr("nothing low"));const describeQty = (raw: string): string =>  match (parseQty(raw)) {    Ok(n) => `qty ${n}`,    Err(e) => match (e) {      Error(err) => err.message,      RangeError(err) => err.message,    },  };console.log(describeQty("5"));console.log(describeQty("lots"));console.log(describeQty("-1"));