import { P, matchWalk } from "matchigo";
function classify(value: unknown, thresholds: { hi: number; lo: number }) {
return matchWalk<unknown, string>(value, [
{ with: P.when((n: number) => n > thresholds.hi), then: () => "hi" },
{ with: P.when((n: number) => n < thresholds.lo), then: () => "lo" },
{ otherwise: () => "mid" },
]);
}
Cold-path companion to match. Walks the pattern tree on every call with zero closure allocation. Slower than compile() on a hot path, faster when rules genuinely change per call (user input, per-request config, one-off factory matches). If you can hoist, prefer match()/matcher().