✨ Add initial pattern-matching API

Introduce the core builder and pattern constructors:

- match(value): chain .with(pattern, handler) and terminate with
  .exhaustive() (throws on no match) or .otherwise(handler).
- P.literal, P.type, P.when, P.any, P.shape for pattern construction.
- Each pattern is a Matcher<T> whose matches acts as a type guard, so
  handler parameters are narrowed to the matched type.

The MatchBuilder accumulates handlers and returns a new builder per
.with() call (immutable chaining); finalization runs the cases in order
and returns the first match's handler result.

TypeScript configuration relaxed in .oxlintrc.json:
- Disable eslint/no-undefined (we use undefined as the no-match sentinel)
- Disable eslint/sort-keys (handler order matters; alphabetical would
  be wrong)
- Disable eslint/id-length (T/R/U/V generics are standard TS convention)
- Disable import/no-named-export (false positive for library entry points)

Verified:
- tsc --noEmit passes with strict + noUncheckedIndexedAccess
- tsc -p tsconfig.build.json emits dist/*.js + .d.ts + sourcemaps
- node -e "import('./dist/index.js')" loads and exposes { match, P }
This commit is contained in:
tmu committed 2026-09-03 10:35:34 +00:00
1 parent 6c67e91e68
commit 08384bbc82
4 files changed
+160 -2

No files matched your search

+6 -1
View File
@@ -14,7 +14,12 @@
"restriction": "error",
"nursery": "off"
},
"rules": {},
"rules": {
"eslint/no-undefined": "off",
"eslint/sort-keys": "off",
"eslint/id-length": "off",
"import/no-named-export": "off"
},
"env": {
"builtin": true,
"es2024": true,