Powerful pattern matching and conditional expressions
Exhaustive pattern matching and functional conditionals without early returns
Match provides exhaustive pattern matching for Scala-style case expressions, while Cond offers functional conditional evaluation without early returns or if-else chains.
// Pattern matching with Match
type Status = "pending" | "approved" | "rejected" | "cancelled"
const processStatus = (status: Status) =>
Match(status)
.caseValue("pending", "Waiting for review")
.caseValue("approved", "Request accepted")
.caseValue("rejected", "Request denied")
.caseValue("cancelled", "Request cancelled")
.default("Unknown status")
const message = processStatus("approved") // "Request accepted"
Type-safe pattern matching with default case enforcement
Functional style without breaking out of expressions
Full TypeScript type inference for all branches
Chain multiple conditions and patterns together
const status = "pending"
Match(status)
.when("pending", () => "⏳ Pending")
.when("success", () => "✓ Success")
.when("error", () => "✗ Error")
.default(() => "Unknown")
const value = 5
Cond.of<string>()
.when(value < 0, "negative")
.elseWhen(value === 0, "zero")
.elseWhen(value > 0, "positive")
.else("unknown")
const option = Option("value")
option.match({
Some: (value) => `Found: ${value}`,
None: () => "Not found",
})
const either = Right<string, string>("success")
either.match({
Right: (value) => `Success: ${value}`,
Left: (error) => `Error: ${error}`,
})
Status codes, state machines, command handlers
Functional programming style, expression-based code
Option, Either, Try, List - built-in match methods