Pattern matching construct similar to Scala's match expressions. Enforces exhaustive matching and returns values.
const result = Match(value) .case(x => x > 100, "large") .case(x => x > 50, "medium") .default("small") Copy
const result = Match(value) .case(x => x > 100, "large") .case(x => x > 50, "medium") .default("small")
// Matching exact valuesconst message = Match(status) .caseValue("pending", "Please wait...") .caseValue("success", "Completed!") .caseValue("error", "Failed") .default("Unknown") Copy
// Matching exact valuesconst message = Match(status) .caseValue("pending", "Please wait...") .caseValue("success", "Completed!") .caseValue("error", "Failed") .default("Unknown")
Add a case with a predicate
Add a case that matches a specific value
Add a case that matches multiple values
Default case - required to get result
Get result if a case matched, throws if no match
Pattern matching construct similar to Scala's match expressions. Enforces exhaustive matching and returns values.
Example
Example