Hyperlinkv0.8.0-beta.28

Match

Match.Wheninterfaceeffect/Match.ts:197
When

Represents a positive pattern matching case.

Details

A When case contains the logic to test if a value matches a specific pattern and the function to evaluate when the pattern matches. It's the primary building block for pattern matching conditions.

Example (Creating positive match cases)

import { Match } from "effect"

// When creates cases that match specific patterns
const stringMatcher = Match.type<string | number>().pipe(
  Match.when(Match.string, (s: string) => `Got string: ${s}`),
  Match.when(Match.number, (n: number) => `Got number: ${n}`),
  Match.exhaustive
)

console.log(stringMatcher("hello")) // "Got string: hello"
console.log(stringMatcher(42)) // "Got number: 42"
models
Source effect/Match.ts:1975 lines
export interface When {
  readonly _tag: "When"
  guard(u: unknown): boolean
  evaluate(input: unknown): any
}
Referenced by 1 symbols