Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Text · 24 lines · 641 B · at 503e839

import { Some, None, Ok, Err, type Option, type Result } from "@tsus/runtime";type Config = { retries: Option<number> };const loadConfig = (raw: string): Result<Config, "empty config"> => {  if (raw === "") {    return Err("empty config");  }  const n = Number(raw);  return Ok({ retries: Number.isNaN(n) ? None : Some(n) });};const describe = (raw: string): string =>  match (loadConfig(raw)) {    Ok(cfg) => match (cfg.retries) {      Some(n) => `retries=${n}`,      None => "retries=default",    },    Err(e) => `broken: ${e}`,  };console.log(describe("3"));console.log(describe("lots"));console.log(describe(""));