// Data-first
const out = match({ kind: "click", x: 1, y: 2 } as Event)
.with({ kind: "click" }, (e) => e.x + e.y)
.with({ kind: "key" }, () => -1)
.exhaustive();
// Curried — build a reusable matcher
const describe = match<Event>()
.with({ kind: "click" }, (e) => `click @ ${e.x},${e.y}`)
.with({ kind: "key" }, (e) => `key ${e.code}`)
.exhaustive();
Start a pattern-matching expression. Two call shapes:
match(value) — data-first; subsequent .exhaustive() or
.otherwise(fn) runs immediately against value.match<T>() — curried; subsequent .exhaustive() returns a function
(value: T) => R for use in pipe(...) or as a reusable matcher.// Data-first
const out = match({ kind: "click", x: 1, y: 2 } as Event)
.with({ kind: "click" }, (e) => e.x + e.y)
.with({ kind: "key" }, () => -1)
.exhaustive();
// Curried — build a reusable matcher
const describe = match<Event>()
.with({ kind: "click" }, (e) => `click @ ${e.x},${e.y}`)
.with({ kind: "key" }, (e) => `key ${e.code}`)
.exhaustive();
Start a pattern-matching expression. Two call shapes:
match(value)— data-first; subsequent.exhaustive()or.otherwise(fn)runs immediately againstvalue.match<T>()— curried; subsequent.exhaustive()returns a function(value: T) => Rfor use inpipe(...)or as a reusable matcher.