import { Ok, Err, tag, type Result, type Tagged } from "@tsus/runtime";type PortError = Tagged<"NotANumber", string> | Tagged<"OutOfRange", number>;const parsePort = (raw: string): Result<number, PortError> => { const n = Number(raw); if (Number.isNaN(n)) { return Err(tag("NotANumber", raw)); } if (n < 1 || n > 65535) { return Err(tag("OutOfRange", n)); } return Ok(n);};const explain = (e: PortError): string => match (e) { NotANumber(raw) => `not a number: ${raw}`, OutOfRange(n) => `out of range: ${n}`, };const report = (raw: string): string => match (parsePort(raw)) { Ok(port) => `listening on ${port}`, Err(reason) => `bad port (${explain(reason)})`, };console.log(report("8080"));console.log(report("banana"));console.log(report("99999"));