Headpats
Pattern matching and tagged unions in JavaScript without new syntax.
See the guide on how to use Headpats!
Refer to the documentation for specific information on pattern matching and built-in features.
Examples
Setup
const pat = ;const $ $$ _ is rest = pat;
Stringly Typed
{ return pat operation;} → 3 → -1 → NaN
Safe Traversal
const o = x: y: z: 10 ; pat→ z: 10 pat→ null
Result Matching
const ok = Symbol'ok';const err = Symbol'err'; { if b === 0 return err null; return ok a / b;} pat;→ num: 5
Option Type
const Option = pat;const Some None = Option; const double = pat ; → Some x: 10 → None {} → Error
Recursive Map
const map = pat ; → 2 4 6 8