Module itinera/option

Option, Some and None, as ts-results-es defines them, which an optional request and a typed read of the data bag give.

Some(value) holds what is present, a stored null included, and None says that nothing is, so the two can never be confused. Import them only from itinera: an ESM application importing them from ts-results-es directly gets a second copy of their types, which does not type-check against itinera's. Their methods, such as unwrapOr and map, are documented by ts-results-es.

import assert from "node:assert/strict";
import { None, type Option, Some } from "itinera/option";

function coupon(present: boolean): Option<string> {
return present ? Some("WELCOME") : None;
}

assert.equal(coupon(true).unwrapOr("none"), "WELCOME");
assert.equal(coupon(false).unwrapOr("none"), "none");